ãããè¡ãã«ã¯ããã¹ãçšã®æãåçŽãªã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã ãŠãŒã¶ãŒã«ã¯ã質åãšããã€ãã®åçãªãã·ã§ã³ãå«ãç»åã衚瀺ãããŸãã ãµãã«ãŒã®ããŒããéžæããŸããïŒãªãã§ããïŒïŒã
ããã¯åŠè¡çãªåé¡ã®ããªãšãŒã·ã§ã³ã§ãããšèšããã®ã§ããã®èšäºã§ã¯ã¢ããªã±ãŒã·ã§ã³ããžãã¯ã«çŠç¹ãåœãŠãŸããã 代ããã«ãã¢ããªã±ãŒã·ã§ã³èªäœãäœæããæé ã詳现ã«èª¬æããŸãã
ã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³çšã®DBMSã®æãèªç¶ãªéžæã¯SQLiteã§ãã ããŒã¿ããŒã¹ãããŒãžã£ãŒãšããŠãSQLite Expertã®ç¡æããŒãžã§ã³ãŸãã¯ãã®ä»ã®è£œåã䜿çšããŠSQLiteãæäœã§ããŸãã
ããŒã¹ã«ã¯ããµãã«ãŒã«é¢ããæ å ±ãä¿åãããåäžã®ããŒãã«ãå«ãŸããŸãã ããŒãã«ã®äœæã«äœ¿çšãããSQLã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
CREATE TABLE [Player] ( [Id] INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT, [PlayerName] CHAR(100) NOT NULL, [TeamNumber] INTEGER, [Height] INTEGER, [Weight] INTEGER, [Photo] BLOB, [CountryId] INTEGER);
å®éããã®èšäºã§ã¯ãIdãPlayerNameãããã³Photoãã£ãŒã«ãã®ã¿ã䜿çšããŸãã æ®ã-æªæ¥ã«è§Šããã SQLite Expertã䜿çšããŠãããŒãã«ã«ãã¹ãããŒã¿ãå ¥åããããšãã§ããŸãã
ããŒã¹ã®æºåãå®äºãããšãããã°ã©ã ã®äœæã«çŽæ¥é²ã¿ãŸãã
XE7ã§ã¯ãFireMonkeyã¢ããªã±ãŒã·ã§ã³ãäœæããæ¹æ³ãå°ãå€æŽãããŸããã çŸåšãããã¹ã¯ãããããšã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã®éã«æ ¹æ¬çãªéãã¯ãããŸããã ãã®çµæãã¢ããªã±ãŒã·ã§ã³ãäœæãããšãã«ããã«ãããã€ã¹ã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒããéžæããŸãã
ãã®ãããªãããžã§ã¯ãã¯ãDelphiãWindowsãOS XãIOSãAndroidã§ãµããŒããããŠãããã©ââãããã©ãŒã ã®ããããã®å®è¡å¯èœãã¡ã€ã«ãçæã§ããŸãã ãããžã§ã¯ãã®äœæäžã«ç¹å®ã®ãã©ãããã©ãŒã ãéžæããããç¹å®ã®çš®é¡ã®ããã€ã¹çšã«ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãã«ã¹ã¿ãã€ãºãããã§ããŸãã
以åã®ããŒãžã§ã³ãšåæ§ã«ã[ãã«ãããã€ã¹ã¢ããªã±ãŒã·ã§ã³ã¿ã€ãã®éžæ]ãã€ã¢ãã°ã䜿çšããŠãã¡ã€ã³ãããžã§ã¯ããã©ãŒã ã®ãã³ãã¬ãŒããéžæã§ããŸãã
ãã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã¿ãä»ããã³ãã¬ãŒããé©ããŠããŸãã
ãŸãã FireDACã䜿çšããŠããŒã¿ããŒã¹ãžã®æ¥ç¶ãæ§æããŸãã ãããè¡ãã«ã¯ãTFDConnectionãTFDPhysSQLiteDriverLinkãTFDGUIxWaitCursorã®3ã€ã®ã³ã³ããŒãã³ããé çªã«ãã©ãŒã ã«é 眮ããŸãã TFDConnectionã³ã³ããŒãã³ããããã«ã¯ãªãã¯ãããšãæ¥ç¶ãšãã£ã¿ãŒãåŒã³åºãããŸãã ããã§ãããŒã¿ããŒã¹ãžã®ãã¹ãæå®ããå¿ èŠããããŸãã LoginPromptãFalseã«èšå®ããŸãã
質åãšåçã®ãªã¹ããäœæããã«ã¯ã2ã€ã®SQLã¯ãšãªãäœæããå¿ èŠããããŸãã ãããã®ã¯ãšãªã¯ãTFDQueryã³ã³ããŒãã³ãã䜿çšããŠåŒã³åºãããŸãã
æåã®ã¯ãšãªã¯ã5人ã®ã©ã³ãã ãªãã¬ãŒã€ãŒããªã¹ãããŸãã
SELECT * FROM Player ORDER BY Random() Limit 5
å®éãããã¯è³ªåã®ãªã¹ãã«ãªããŸãã
2çªç®ã®ãªã¯ãšã¹ãã¯æåã®ãªã¯ãšã¹ããšäŒŒãŠããŸãããå¯äžã®éãã¯ãã¬ãŒã€ãŒã®1人ããã®ãªã¹ãã«å ¥ããªãããšã§ãã
SELECT * FROM Player WHERE Id<> :Id ORDER BY Random() Limit 4
ããã¯ãå質åã«å¯ŸããŠçæãããåçã®ãªã¹ãã§ãã æåã§æ¿å ¥ãããæ£è§£ã¯ãªã¹ãããé€å€ãããŸãã
XE7ã®æŽæ°ãããã¯ãŒã¯ã¹ããŒã¹ãã¶ã€ããŒã詳ããèŠãŠã¿ãŸãããã ã¡ã€ã³ããŒã«ããŒã®ããäžã«ç¬èªã®ããŒã«ããŒããããŸãã ãã®ããã«ã«ã¯ã2ã€ã®ãã¿ã³ãš2ã€ã®ããããããŠã³ãªã¹ããå«ãŸããŠããŸãã
XE5 / XE6ã§å©çšå¯èœã§ãã£ããªã¹ã-ã¹ã¿ã€ã«ã®ãªã¹ãã«çœ®ãæãããã
æåºã®ãªã¹ãã ããã€ã¹ã®åããå€æŽããããããã€ã¹ãã¹ã¯ã衚瀺ãããããããã®ãã¿ã³ã
æåã®ãªã¹ãã§ã¯ãéçºããã»ã¹äžã®ã€ã³ã¿ãŒãã§ãŒã¹ã®å€èŠ³ãéžæã§ããŸãã
å°ãåŸã§2çªç®ã®ãªã¹ãã«æ»ããŸãã ãããŸã§ã®éããã©ãŒã ã«å¿ èŠãªã³ã³ãããŒã«ãé 眮ããç®çã®ã³ãŒããäœæããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®TTabControlãã³ãã¬ãŒãã®åºæ¬èŠçŽ ã«ã¯ããã¹ãäžã«é çªã«åãæ¿ãã3ã€ã®ã¿ããå«ãŸããŸãã ãŠãŒã¶ãŒãã©ã³ãã ãªé åºã§ã¿ããæåã§åãæ¿ããããšãã§ããªãããã«ãTabPositionããããã£ãNoneã«èšå®ããŸãã
æåã®ã¿ãã§ã2ã€ã®ãã¿ã³ãé 眮ããŸãã ãããå³ã«ç€ºãããã«ã
ãçµäºããã¿ã³ã¯ãã¢ããªã±ãŒã·ã§ã³ãéããŸãã
procedure TfMain.btnExitClick(Sender: TObject); begin Close; end;
ãNew Gameããã¿ã³ã¯ããæ³åã®ãšããããã¹ãæé ãéå§ããŸãã
ãã¿ã³ãæŒããšã次ã®ããã«åŠçãããŸãã
procedure TfMain.btnNewGameClick(Sender: TObject); begin qPlayer.Close; qPlayer.Open; // qPlayer.First; TrueCount := 0; TabControl1.TabIndex := 1; FormAnswers(4); end;
ãã¿ã³ãã¯ãªãã¯ãããšã2çªç®ã®ã¿ããã¢ã¯ãã£ãã«ãªããŸãã
ãã¬ãŒã€ãŒã®ç»åãå·ŠåŽã«è¡šç€ºãããå³åŽã«pAnswersããã«ã衚瀺ãããŸã-åçãªãã·ã§ã³ã®ãªã¹ãã
procedure TfMain.FormAnswerArray(Count, qId: integer); var aPos, i: integer; rb: TRadioButton; BlobStream: TStream; begin Randomize; aPos := Random(Count - 1); try BlobStream := qPlayer.CreateBlobStream(qPlayer.FieldByName('Photo'), TBlobStreamMode.bmRead); Image1.Bitmap.LoadFromStream(BlobStream); finally BlobStream.Free; end; qAnswer.Close; qAnswer.ParamByName('Id').AsInteger := qId; qAnswer.Open; i := 0; while not qAnswer.Eof do begin if i > Count then Break; try rb := TRadioButton.Create(pAnswers); rb.Position.X := 0; // Image1.Position.X +10; rb.Position.Y := i * 20; rb.Parent := pAnswers; pAnswers.InsertComponent(rb); rb.Size.Width := 250; finally end; if i = aPos then begin rb.Text := qPlayerPlayerName.AsString; rb.Tag := qPlayerId.AsInteger; end else begin rb.Text := qAnswerPlayerName.AsString; rb.Tag := qAnswerId.AsInteger; qAnswer.Next; end; Inc(i); end; end; procedure TfMain.ClearRadioButtons; var i, j: integer; begin for i := pAnswers.ChildrenCount - 1 downto 0 do begin if pAnswers.Children[i].ClassNameIs('TRadioButton') then begin (pAnswers.Children[i] as TRadioButton).Visible := FAlse; pAnswers.Children[i].Free; end; end; pAnswers.Repaint; end; procedure TfMain.FormAnswers(Count: integer); begin ClearRadioButtons; FormAnswerArray(Count, qPlayerId.AsInteger); end;
TrueCountå€æ°ã«ã¯ãæ£è§£ã®æ°ãå«ãŸããŸãã FormAnswersæç¶ã-åçã®ãªã¹ããäœæããŸãã
ã³ãŒãããæšæž¬ããã®ã¯é£ããããšã§ã¯ãªãã®ã§ãTRadioButtonã³ã³ããŒãã³ãã¯pAnswersããã«ã«è¿œå ãããŸãããã®ããã«ããããã£ã®Textããããã£ã«ã¯ãã¬ãŒã€ãŒã®å§ãå€ãšããŠå«ãŸããTagããããã£ã¯Idã§ãã ãã®å Žåãæ£ãããªãã·ã§ã³ã¯æåã®ã¯ãšãªïŒqPlayerïŒã®çµæããååŸãããééã£ããªãã·ã§ã³ã¯2çªç®ã®ã¯ãšãªïŒqAnswerïŒã®çµæããååŸãããŸãã æ£è§£ã®äœçœ®ã¯ã©ã³ãã ã§ãã
[次ãž]ãã¯ãªãã¯ãããšã次ã®ã³ãŒããåŒã³åºãããŸãã
procedure TfMain.btnNextClick(Sender: TObject); var answID: integer; begin answID := GetAnswerID; Inc(cnt); if answID = qPlayerId.AsInteger then begin Inc(TrueCount); ShowMessage(''); end else begin ShowMessage(' '); end; if qPlayer.RecNo <> 5 then begin qPlayer.Next; FormAnswers(4); end else begin TabControl1.TabIndex := 2; end; // if qPlayer.Eof then if qPlayer.RecNo = 5 then begin lResult.Text := ' ' + IntToStr(TrueCount) + ' 5'; btnNext.Text := ''; end; end;
GetAnswerIDé¢æ°ã¯æ¬¡ã®ããã«å®è£ ãããŸãã
function TfMain.GetAnswerID: integer; var i, j, k: integer; begin Result := -1; for i := tiQuest.ChildrenCount - 1 downto 0 do begin if tiQuest.Children[i].ClassNameIs('TTabItemContent') then begin for j := tiQuest.Children[i].ChildrenCount - 1 downto 0 do begin if tiQuest.Children[i].Children[j].ClassNameIs('TPanel') then for k := tiQuest.Children[i].Children[j].ChildrenCount - 1 downto 0 do if tiQuest.Children[i].Children[j].Children[k].ClassNameIs ('TRadioButton') then if (tiQuest.Children[i].Children[j].Children[k] as TRadioButton).IsChecked then begin Result := (tiQuest.Children[i].Children[j].Children[k] as TRadioButton).Tag; Break; end; end; end; end; end;
3çªç®ã®ã¿ãã«ã¯çµæã衚瀺ãããŸãã
Delphi XE7ã§ãã«ããã©ãããã©ãŒã ã¢ããªã±ãŒã·ã§ã³ãæ§ç¯ããããã®æ°ããæ¹æ³è«ã¯ãæåã«ãã¹ã¿ãŒãã¥ãŒã䜿çšããŠãã©ãŒã ã«å¿ èŠãªãã¹ãŠã®ã³ã³ããŒãã³ããé 眮ãããšããäºå®ã«èŠçŽãããŸã ã 次ã«ããããžã§ã¯ããçæããäºå®ã®åãã©ãããã©ãŒã ãšããã€ã¹ã®ã¿ã€ãããšã«ç¹å¥ãªãã¥ãŒãäœæããŸãã æåŸã«ãåãã¥ãŒãåå¥ã«ã«ã¹ã¿ãã€ãºããŸãã
ãããŸã§ã«è¡ã£ããã¹ãŠã®ããšã¯ããã¹ã¿ãŒã«ãã£ãŠè¡ãããŸããã
Windowsã§å®è¡ããããã«ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããšïŒä»¥åã®ããã«ããããžã§ã¯ããããŒãžã£ãŒã§ã¿ãŒã²ãããã©ãããã©ãŒã ãéžæããå ŽåïŒãã¡ã€ã³ãã©ãŒã ã¯ãã¶ã€ããŒãšã»ãŒåãã«ãªããŸãã
ãã ãããªã¹ãããé©åãªãã¥ãŒãéžæããŠãåå¥ã«æ§æã§ããããã«ãªããŸããã å®éã«ã©ã®ããã«èŠãããèŠãŠã¿ãŸãããã
ãªã¹ãããéžæããã ãã§Windowsãã¹ã¯ãããã®ãã¥ãŒãè¿œå ããã¹ã¿ã€ã«ããªã³ã«ããŸãã ãããè¡ãã«ã¯ãStyleBookã³ã³ããŒãã³ãã䜿çšããŸãã
Windowsã§åäœããã¢ããªã±ãŒã·ã§ã³ã¯æ¬¡ã®ããã«ãªããŸãã
ããã¯ãWindowsãã¹ã¯ããããã¢ã¯ãã£ããªãšãã«disinerã®ãã©ãŒã ãã©ã®ããã«èŠãããã§ãã
ãããããã¹ã¿ãŒã®å°å ¥ã«ã€ããŠã¯ãå€æŽã¯çºçããŸããã
ãã¥ãŒã®1ã€ã§è¡ã£ãå€æŽãä»ã®ãã¥ãŒã«åœ±é¿ãäžããªãããšãç解ããããšãéèŠã§ãã ãããããã¹ã¿ãŒã®ãã¥ãŒãå€æŽãããšããã®ãããªå€æŽã¯ã暪æçãã«ãªããŸãã åœç¶ããã®ã¢ãããŒãã«ã¯ç¹å®ã®å¶éããããŸãã ç°¡ç¥åããããã©ãŒã ã§ã¯ããã©ãŒã äžã®ãã¹ãŠã®è¡šçŸãåãã³ã³ããŒãã³ãã®ã»ãããæããªããã°ãªããªããšããäºå®ã«èŠçŽãããŸãã 1ã€ã®ãã¥ãŒããã³ã³ããŒãã³ããåé€ããŠãä»ã®ãã¥ãŒã«æ®ãããšã¯ã§ããŸããã ãã ããåãã¥ãŒã§ã³ã³ããŒãã³ãã®ããããã£ãåå¥ã«å®å šã«å€æŽã§ããŸãã
ãã®ã¢ãããŒãã¯ãããçšåºŠã®æè»æ§ããããããŸãã Androidçšã®ã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ãäœæãããšãã«FireUIã¡ã«ããºã ãã©ã®ããã«æ©èœããããèŠãŠã¿ãŸãããã
ãŸããããŒã¹ãã¢ãã€ã«ããã€ã¹ã«è»¢éããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã以åã®ããŒãžã§ã³ã§ããç¥ãããŠããDeployment Managerã䜿çšããŸãã
Delphiã®ä»¥åã®ããŒãžã§ã³ãšåæ§ã«ãFDConnectionã³ã³ããŒãã³ãã®BeforeConnectionã€ãã³ããåŠçããå¿ èŠããããŸãã
procedure TfMain.FDConnection1BeforeConnect(Sender: TObject); begin {$IFDEF ANDROID} FDConnection1.Params.Values['Database'] := IncludeTrailingPathDelimiter (System.IOUtils.TPath.GetDocumentsPath) + 'tests.db'; {$ENDIF} end;
ãã®åŸãã¢ãã€ã«ããã€ã¹ãæ¥ç¶ãã察å¿ãããã¥ãŒãäœæããŸãã
ã³ã³ãããŒã«ã®ã¹ã¿ã€ã«ãšå Žæãèšå®ããã¢ãã€ã«ããã€ã¹ã§ã¢ããªã±ãŒã·ã§ã³ãå®è¡ããŸãã ã¢ããªã±ãŒã·ã§ã³ã®å€èŠ³ã¯å®å šã«ç°ãªããŸãããæããã«ããŸã£ããåãã¢ããªã±ãŒã·ã§ã³ã§ãã
ããã«ãFDConnectionã³ã³ããŒãã³ãã®BeforeConnectionã€ãã³ããã³ãã©ãŒãå€æŽããå¿ èŠããããŸãã
procedure TfMain.FDConnection1BeforeConnect(Sender: TObject); begin FDConnection1.Params.Values['Database'] := IncludeTrailingPathDelimiter (System.IOUtils.TPath.GetDocumentsPath) + 'tests.db'; end;
ãŸããã¢ããªã±ãŒã·ã§ã³ãWindowsã§åäœãç¶ããããã«ãWindowsãã¹ã¯ããããã¥ãŒã§ã¯ãã®ã€ãã³ããåŠçããŸããã
ãã®ãããäžè¬çã«ã¯ãFireUIã®åºçŸã«ããFireMonkeyã¢ããªã±ãŒã·ã§ã³ãéçºããããã®æ¹æ³è«ã«ã©ã®ãããªå€åãèµ·ãã£ãã®ããèŠãŸããã ä»ãç§ãã¡ã¯ãåäžã³ãŒãããŒã¹ããšç°ãªããã©ãããã©ãŒã çšã®ããã€ãã®ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠã§ã¯ãªããå®éã«ã¯åãã©ãããã©ãŒã çšã«æ§ç¯ãããåäžã®ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠè©±ããŠããŸãã
次ã®èšäºã§ã¯ãããŸããŸãªãã©ãããã©ãŒã ããµããŒãããã¢ããªã±ãŒã·ã§ã³ã«èŠããããèœãšãç©ŽããåæããŸãã äžç·ã«ããŠãã ããã
æŽæ°1ïŒ
2ã€ã®ããã€ã¹ã§ã¢ããªã±ãŒã·ã§ã³ãèµ·åããŸãã