ããŒã1
ã·ãªãŒãºã®åã®ããŒãã§ã¯ãæ°ããRAD Studio XE5ã®äž»ãªæ©èœã確èªããŸããã ä»æ¥ã¯ãç·Žç¿ã«ç§»ããŸãããã ãŸããã¿ã¹ã¯ã決å®ããŸãããã
åé¡ã®å£°æ
ã¢ã«ãããã¯ãªã¿ã¹ã¯ãããã€ããããŸãããäŸãšããŠã¯ãã¯ããã¯ãéžæããŸããã ãŸããéçºããã¢ããªã±ãŒã·ã§ã³ã«ç¬åµæ§ãæãããããã«ãããã€ãã®è¿œå æ©èœã䜿çšããŠããã®ãããªããã°ã©ã ã®éåžžã®æ©èœãæ¡åŒµããããšããŸãã
å¿ èŠãªè£œåã®éã®åèšç®ã
éåžžãã¬ã·ãã¯äœ¿çšããã補åã®æ£ç¢ºãªéã瀺ããŸãã ãããããµãŒãã³ã°ã®æ°ãå€æŽãããå Žåã¯ãããã«å¿ããŠã補åã®æ°ãåã«ãŠã³ãããå¿ èŠããããŸãã æçãæºåããéçšã§ãããã¯å¿ ããã䟿å©ã§ã¯ãããŸããã
ã¿ã€ããŒ
æçã«æ £ããŠããªãå Žåã¯ãç¹å®ã®æäœã®æéãæ確ã«ç€ºãã¬ã·ãã䜿çšããå¿ èŠããããŸãã ãŸããã¿ãã¬ãããé»è©±ããŸãã¯ãããããã¯ã®ã¿ã€ããŒã¯ããããã³ã¿ã€ããŒã®äŸ¿å©ãªä»£æ¿åã«ãªããŸãã
å€ãã®å Žåãè€æ°ã®æäœã䞊è¡ããŠå®è¡ãããŸãã åæäœã«ã¯ç¬èªã®ãã¿ã€ããŒããèšå®ã§ããŸãã
åæã«ãã¢ããªã±ãŒã·ã§ã³ã®ããã¹ã¯ãããããšã¢ãã€ã«å®è£ ã®äž¡æ¹ã«é¢å¿ããããŸãã ã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã¯ãã¬ã·ããèŠèŠåããæºåããã»ã¹ã«ä»éããããŒã«ãšããŠäœ¿çšãããŸãã ãã¹ã¯ãããããŒãžã§ã³ã¯ãæ°ããã¬ã·ãã®äœæãªã©ãããé«åºŠãªæ©èœã§äœ¿çšã§ããŸãã
ååãšããŠãããã°ã©ãã³ã°ã®æ¬ã®ãããªæçã®æ¬ã¯ãèªè ã®æºåã®ããŸããŸãªã¬ãã«ã«åãããŠèšèšã§ããããšã«æ³šæããŠãã ããã ç§ãã¡ã®å ŽåãããããŒã®ã¬ã·ãããã€ãŸã補åã®æ£ç¢ºãªæ°ãšç¹å®ã®ã¢ã¯ã·ã§ã³ã®æ£ç¢ºãªæéã瀺ããã®ã«ã€ããŠè©±ããŠããŸãã
ãã®ã¢ããªã±ãŒã·ã§ã³ãWindowsããã³Androidåãã«å®è£ ããŠããŸãã 次ã«ãåäžã®ãœãŒã¹ã³ãŒãããŒã¹ã«åºã¥ããŠãã¢ããªã±ãŒã·ã§ã³ãMacOSããã³iOSã«ç§»æ€ã§ããŸãã
éçºããŒã«ã®éžæ
éçºã«çŽæ¥é²ãåã«ãããŒã«ã決å®ããŸãããã ãã¡ãããã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšãããããŒã¿ã¯ãæãé©åã«ã¯ããŒã¿ããŒã¹ã«ä¿åãããŸãã
å®éšã®çŽåºŠã®ããã«ã SQLiteãDBMSãšããŠäœ¿çšããŸãã ãã®DBMSã«ã¯ãé床ã䜿ããããããªãœãŒã¹ã«é¢ããè²»çšå¯Ÿå¹æãªã©ãå€ãã®å©ç¹ããããŸãã åçŽãªã¿ã¹ã¯ã«æé©ã§ãããããã«Androidã«ã¯SQLiteãµããŒããçµã¿èŸŒãŸããŠããŸãã
å°æ¥çã«ã¯ã InterBase DBMSã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ã移è¡ããæ¹æ³ãæ€èšããEmbarcaderoã®ããã€ãã£ãããœãªã¥ãŒã·ã§ã³ã®ãã¹ãŠã®å©ç¹ã瀺ããŸãã
ã¢ããªã±ãŒã·ã§ã³ãšãšãã«ãåå¥ã«äœæãããæ¢è£œã®DBMSãé åžããŸãã ãã®ã¢ãããŒãã¯ãã¿ã¹ã¯ã®è©³çŽ°ã«ãããã®ã§ãã
ãã¡ããã Delphi XE5ãå¿ èŠã§ã ã Windowsã¢ããªã±ãŒã·ã§ã³ãäœæããã«ã¯ãååãšããŠã Professionalãšãã£ã·ã§ã³ã«å¶éããããšãã§ããŸãã ãããããããã ã¢ãã€ã«éçºã§ã¯ãå°ãªããšãEnterpriseãšãã£ã·ã§ã³ã®è£œåãå¿ èŠã§ãã ãŸãã¯ã Delphi XE5 Professionalã®ã¢ãã€ã«ã¢ããªã³ããã¯ã䜿çšããŸãã
Windowsã§SQLiteã䜿çšããã«ã¯ãå ¬åŒWebãµã€ãããsqlite-dll-win32-x86-3080100.zipã©ã€ãã©ãªãããŠã³ããŒãããå¿ èŠããããŸãã ãã®ã©ã€ãã©ãªãã·ã¹ãã ãã©ã«ãã®1ã€ïŒããšãã°ãWindows / SYSTEM32ïŒã«é 眮ããæãç°¡åãªæ¹æ³ã
çŸåšãéåžžã«å€ãã®ç¡æã®SQLiteããŒã¿ããŒã¹ç®¡çããŒã«ããããŸãã ãã®ãã¡ã®1ã€ã䜿çšããããšãã§ããŸãã
FireDACã©ã€ãã©ãªã䜿çšããŠãã¢ããªã±ãŒã·ã§ã³ããããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããŸãã
FireDACã¯ãããŸããŸãªããŒã¿ããŒã¹ã«æ¥ç¶ããã¢ããªã±ãŒã·ã§ã³ãéçºããããã«èšèšããããŠãããŒãµã«ããŒã¿ã¢ã¯ã»ã¹ã©ã€ãã©ãªã§ãã FireDACã䜿çšãããšãVCLãšFireMonkeyã¢ããªã±ãŒã·ã§ã³ã®äž¡æ¹ãéçºã§ããŸãã ãã®ã©ã€ãã©ãªã¯ã InterBase ã SQLite ã MySQL ã SQL Server ã Oracle ã PostgreSQL ã DB2 ã SQL Anywhere ã Advantage DB ã Firebird ã Access ã Informixã® DBMSããµããŒãããŠããŸãã ãã ãããã®æ®µéã§ã¯ã FireDACã䜿çšãããçŽæ¥ãïŒDataSnapãã¯ãããžãŒã䜿çšããªãïŒã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã§ã¯ã SQLiteãšInterBaseã«ã®ã¿æ¥ç¶ã§ããŸãã
ããŒã¿ããŒã¹äœæ
ããŒã¿ããŒã¹æ§é ãäœæããŠãéçºããã»ã¹ãéå§ããŸãã ãã®è«çã¢ãã«ãå³ã«ç€ºããŸãã
ãã®ãã£ãŒãã¯ãEmbarcadero Technologies- ER / Studioã®å¥ã®ããŒã«ã䜿çšããŠååŸãããŸããã ãã®è£œåã®Developer Editionã¯ã RAD Studio Architectã®ãŠãŒã¶ãŒãå©çšã§ããŸãã ãã®åºçç©ã®æ çµã¿ã§ã¯ã ER / Studioã®èª¬æã«ã€ããŠã¯è§ŠããŸããã ãã®åŒ·åãªããŒã«ã¯ãå¥åã®çŽ æã䜿çšãã䟡å€ããããŸãã
ããŒã¿ããŒã¹æ§é ãäœæãããšããè«çã¢ãã«ã®åãšã³ãã£ãã£ã«ã¯ç©çããŒãã«ããããŸãã çµæã®ããŒãã«ã®ç®çãç°¡åã«æ€èšããŠãã ããã
tblFoodstuffããŒãã«ã§ã¯ãå¯èœãªãã¹ãŠã®è£œåã®ãªã¹ããä¿æããŸãã tblUnitããŒãã«ã§ã枬å®åäœïŒã°ã©ã ãã¹ããŒã³ãã°ã©ã¹ãªã©ïŒã®ãªã¹ãã tblRecipeããŒãã«ã«ã¯ãã¬ã·ãã®ãªã¹ããå«ãŸããŠããŸãã ããŒãã«tblIngredientesããã³tblActionã«ã¯ãããããæåïŒ qtyãã£ãŒã«ãã®æ°éã瀺ãïŒãšã¢ã¯ã·ã§ã³ïŒæéãšèª¬æã瀺ãïŒã®ãªã¹ããå«ãŸããŠããŸãã
SQLiteããŒã¿ããŒã¹ãäœæããã«ã¯ã次ã®ã¹ã¯ãªããã䜿çšããã ãã§ãã
CREATE TABLE [tblAction] ( [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [IdRc] INTEGER NOT NULL, [Sec] INTEGER NULL, [DescriptionShort] VARCHAR(128) NOT NULL, [DescriptionExtendent] TEXT NOT NULL ); CREATE TABLE [tblFoodstuff] ( [Id] INTEGER PRIMARY KEY AUTOINCREMENT NULL, [Abbr] VARCHAR(10) NULL, [Title] VARCHAR(50) NULL ); CREATE TABLE [tblIngredientes] ( [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [IdCB] INTEGER NOT NULL, [IdFS] INTEGER NOT NULL, [IdUnit] INTEGER NOT NULL, [qty] INTEGER NULL ); CREATE TABLE [tblRecipe] ( [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [Title] VARCHAR(150) NOT NULL ); CREATE TABLE [tblUnit] ( [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [UnitName] VARCHAR(25) NOT NULL, [Abbr] VARCHAR(7) NOT NULL ); CREATE INDEX [IDX_TBLACTION_Recipe] ON [tblAction]( [IdRc] ASC ); CREATE INDEX [IDX_TBLINGREDIENTES_] ON [tblIngredientes]( [IdCB] ASC ); CREATE INDEX [idxFoodStuff] ON [tblIngredientes]( [IdFS] ASC ); CREATE INDEX [idxRecipe] ON [tblIngredientes]( [IdCB] ASC ); CREATE INDEX [idxUnit] ON [tblIngredientes]( [IdUnit] ASC );
Windowsã¢ããªã±ãŒã·ã§ã³ã®äœæ
ã¢ããªã±ãŒã·ã§ã³éçºããã»ã¹ã次ã®ããã«ç·šæããŸãã ãŸããWindowsçšã®ã¢ããªã±ãŒã·ã§ã³ã®åºæ¬ããŒãžã§ã³ãäœæãããããAndroidãã©ãããã©ãŒã ã«ç§»æ€ããŸãã 次ã«ãäž¡æ¹ã®ã¢ããªã±ãŒã·ã§ã³ã®æ©èœã䞊è¡ããŠæ¡åŒµããŸãã MacOSããã³iOSããŒãžã§ã³ã®ã¢ããªã±ãŒã·ã§ã³ãæçµæ®µéã«ãªããŸãã æ¢è£œã®Windowsããã³AndroidããŒãžã§ã³ãã§ããããäœæãéå§ããŸãã
Delphi IDEã¯ãããã€ãã®æ°ããã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒããæäŸããŸãã ãã®å Žåã FireMonkey Desktop Applicationã«é¢å¿ããããŸã ã
é©åãªã¡ãã¥ãŒé ç®ãéžæãããšãè¿œå ã®ãã€ã¢ãã°ãç»é¢ã«è¡šç€ºãããæ°ããFireMonkeyã¢ããªã±ãŒã·ã§ã³ã®çš®é¡ïŒHDïŒHigh DefinitionïŒãŸãã¯3DïŒãéžæããããã«æ±ããããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ãã©ãŒã ã®ååãå€æŽãïŒãªããžã§ã¯ãã€ã³ã¹ãã¯ã¿ãŒã§Nameããããã£ãå€æŽããŸãïŒãæ°ããäœæãããããžã§ã¯ããä¿åããŸãã ãããžã§ã¯ãã«æ°ããããŒã¿ã¢ãžã¥ãŒã«ãè¿œå ãïŒDelphiãã¡ã€ã«ãã©ã³ãã®[ãã¡ã€ã«] | [ãã®ä»]ã¡ãã¥ãŒïŒãååãå€æŽããŠä¿åããŸãã
ãããã£ãŠãæ°ãããããžã§ã¯ããäœæããéçºã®ããã«çŽæ¥æºåããŸããã
FireDACæ¥ç¶ãæ§æãã
habrahabr.ru/topic/edit/200490/#
æåã«è¡ãå¿ èŠãããã®ã¯ãããŒã¿ããŒã¹æ¥ç¶ã®ã»ããã¢ããã§ãã FireMonkeyã§ã¯ããã®æé ã¯VCLãšå€§ããªéãã¯ãããŸããã
ã³ã³ããŒãã³ãTFDConnection ã TFDGUIxWaitCursorããã³TFDPhysSQLiteDriverLinkãDataModuleã«é 眮ããŸãã ãªããžã§ã¯ãã€ã³ã¹ãã¯ã¿ãŒã§ãTFDConnectionã³ã³ããŒãã³ãã®LoginPromptããããã£ã®å€ãå€æŽããŸãã
LoginPrompt = False
ãã©ãŒã äžã®ã³ã³ããŒãã³ããããã«ã¯ãªãã¯ãããšãæ¥ç¶èšå®ãã€ã¢ãã°ã衚瀺ãããŸãã
ãã®å Žåããã©ã€ããŒIDãšããŠSQLiteãæå®ããDatabaseãã©ã¡ãŒã¿ãŒã®å€ãšããŠããŒã¿ããŒã¹ãã¡ã€ã«ãžã®ãã¹ãæå®ããŸãã [ãã¹ã]ãã¿ã³ã䜿çšããŠèšå®ã確èªã§ããŸãã
å®è¡æã«ããŒã¿ããŒã¹ã«æ¥ç¶ããæ©èœãããã«äœæããŸãã
function TDM.ConnectToDB: Boolean; begin try FDConnection1.Connected := True; except end; Result:= FDConnection1.Connected; end;
ãã®é¢æ°ãã¡ã€ã³ã¢ãžã¥ãŒã«ããåŒã³åºãããã«ããããªãã¯ã»ã¯ã·ã§ã³ã«ãã®ã¿ã€ãã«ãé 眮ããŸãã
äž»ãªç³è«æž
ã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ãã©ãŒã ã§ãã³ã³ããŒãã³ãTGroupBox ã TTabControl ãããã³TSplitterãé çªã«é 眮ããŸãã ãããã®ããããã«Alignããããã£ãèšå®ããŸãïŒãããããalLeftãalLeftãããã³alClientïŒã å·Šããã«ã«TListBoxãšTBindNavigatorã®2ã€ã®ã³ã³ããŒãã³ããé 眮ããŸãã å³ã«ç€ºãããã«é 眮ããŸãã ããã«ã¯ãªãã¯ããŠTTabControlã³ã³ããŒãã³ãã®ãã€ã³ããã¶ã€ããŒãåŒã³åºãã2ã€ã®ãã€ã³ããäœæããŸãã
ã¬ã·ãã®ãªã¹ããã¢ããªã±ãŒã·ã§ã³ã®å·ŠåŽã«è¡šç€ºãããŸãã å³åŽã®ã¿ãã«ã¯ãæçã®ææã®ãªã¹ãïŒéã瀺ãïŒãšãçŽæ¥ãã¬ã·ãã®ç¹å®ã®ã¢ã¯ã·ã§ã³ã®ãªã¹ããããªããªã¹ãããããŸãã
ããŒã¿æ¥ç¶
æ¢ã«è¿°ã¹ãããã«ãFireMonkeyã«ã¯ç¹å¥ãªããŒã¿è¡šç€ºã³ã³ããŒãã³ãã¯ãããŸããã 代ããã«ã LiveBindingãã€ã³ãã£ã³ã°ã¡ã«ããºã ã䜿çšãããŸãã ä»çµã¿ãèŠãŠã¿ãŸãããã ã¬ã·ãã®ãªã¹ããã¡ã€ã³ãã©ãŒã ã®TListBoxã³ã³ããŒãã³ãã«æ¥ç¶ããŸãã ãŸããã¬ã·ãã®ãªã¹ããæäœããããã®ããŒã¿ã»ãããäœæããå¿ èŠããããŸãã ããŒã¿ã¢ãžã¥ãŒã«ã§ã¯ã TFDTableã³ã³ããŒãã³ãã䜿çšããŸãã ããããã£ã次ã®ããã«èšå®ããŸãã
ConnectToDBé¢æ°ã®ã³ãŒãã§ãããŒã¿ã»ãããéãã¡ãœãããžã®åŒã³åºããè¿œå ããŸãã
FDTRecipe.Open;
ã©ã³ã¿ã€ã ã¢ãŒãã§ããŒã¿ããŒã¹ãžã®æ¥ç¶ã確ç«ããã«ã¯ãConnectToDBé¢æ°ãžã®åŒã³åºããè¿œå ããå¿ èŠããããŸãã ããŒã¿ã¢ãžã¥ãŒã«ã®OnCreateã€ãã³ãã«ãã€ã³ãã§ããŸãã
procedure TDM.DataModuleCreate(Sender: TObject); begin DM.ConnectToDB; end;
ã¢ããªã±ãŒã·ã§ã³éçºã®åæ段éã§ã¯ãæ¥ç¶äžã«çºçããå¯èœæ§ã®ããäŸå€ãåŠçããŸããããããã¯å°æ¥è¡ãå¿ èŠããããŸãã
TRecipeããŒãã«ããã®ããŒã¿ã®åºåãã¡ã€ã³ãã©ãŒã ã®ãªã¹ãã«æŽçããŸãã ãããè¡ãã«ã¯ããŸããããã°ã©ã ã®ã¡ã€ã³ãã©ãŒã ã®ã¢ãžã¥ãŒã«ã®Usesã»ã¯ã·ã§ã³ã«ããŒã¿ã¢ãžã¥ãŒã«ãè¿œå ããŸãã
interface uses uDM, System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
ãã©ãŒã ãšãã£ã¿ãŒã§ãã³ã³ããã¹ãã¡ãã¥ãŒãåŒã³åºãã[èŠèŠçã«ãã€ã³ã]ã¢ã€ãã ãéžæããŸãã ç»é¢ã®äžéšã§ã LiveBindingãã¶ã€ããéããŸãã ãã®äžã«ããã€ã¢ã°ã©ã èŠçŽ ã®åœ¢åŒã§ããªããžã§ã¯ããšãã®åºæ¬ããããã£ã衚瀺ãããŸãã ãã©ãã°ã¢ã³ãããããããã ãã§ãå³ã«ç€ºãããã«3ã€ã®ãªããžã§ã¯ãã®ããããã£ãæ¥ç¶ããŸãã
å®éã«ã¯ããããã¬ã·ãããŒãã«ïŒã€ãŸããã¬ã·ãåã®ãªã¹ãïŒããã®ããŒã¿ã衚瀺ããããã«å¿ èŠãªãã¹ãŠã§ãã ããã§ããã°ã©ã ãå®è¡ãããšããªã¹ãã衚瀺ãããŸããã空ã§ãããããã¬ã·ããè¿œå ããæ¹æ³ã«æ³šæããå¿ èŠããããŸãã
æ°ããFireMonkey HDãã©ãŒã ãäœæããŸãã ããããã£ã次ã®ããã«èšå®ããŸãã
Name = fAddRecipe
BorderStyle = bsToolWindow
Position = poMainFormCenter
ããŒã¿ã¢ãžã¥ãŒã«ãæ¥ç¶ããTEditã³ã³ããŒãã³ããš2ã€ã®ãã¿ã³ããã©ãŒã ã«é 眮ããŸãã LiveBindingãã¶ã€ãã§ãTEditã³ã³ããŒãã³ãã®Textããããã£ãããŒã¿ã»ããã®Titleãã£ãŒã«ãã«é¢é£ä»ããŸãã
æ°ãããã©ãŒã©ã ãä¿åããèªåäœæããããã©ãŒã ã®ãªã¹ãããåé€ããŸãïŒ[ãããžã§ã¯ã] | [ãªãã·ã§ã³]ã¡ãã¥ãŒã®[ãã©ãŒã ]ã¿ãïŒã
ã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ãã©ãŒã ã®å Žåãã¡ãœãããäœæããŸãã
procedure TfMain.RecipeAfterInsert(DataSet: TDataSet); var fAddRecipe: TfAddRecipe; begin try fAddRecipe:= TfAddRecipe.Create(Application); fAddRecipe.ShowModal; if fAddRecipe.ModalResult = mrOk then begin if DataSet.State in [dsInsert, dsEdit] then DataSet.Post; end else begin if DataSet.State in [dsInsert, dsEdit] then DataSet.Cancel; end; finally FreeAndNil(fAddRecipe); end; end;
ããã°ã©ã ãèµ·åããããã¬ã·ãããŒã¿ã»ããã®AfterInsertã€ãã³ããå®çŸ©ããŸãã
procedure TfMain.FormShow(Sender: TObject); begin DM.FDTRecipe.AfterInsert:= RecipeAfterInsert; end;
ããã§ãã¢ããªã±ãŒã·ã§ã³ãèµ·åããããšã«ãããããã²ãŒã¿ãŒã䜿çšããŠå€æŽã§ããã¬ã·ãã®ãªã¹ããååŸããŸãã æ°ããã¬ã·ããè¿œå ãããšãå ¥åãã£ãŒã«ãã®ãããã©ãŒã ãç»é¢ã«è¡šç€ºãããŸãã
ã·ãªãŒãºã®ãã®ããŒãã§ã¯ãWindowsçšã®æãåçŽãªFireMonkeyã¢ããªã±ãŒã·ã§ã³ãäœæããŸããã FireDACããã±ãŒãžã䜿çšããŠããŒã¿ããŒã¹ã«æ¥ç¶ããæ¹æ³ãåŠã³ã LiveBindingã䜿çšããæãç°¡åãªäŸãèŠãŠã¿ãŸãã ã
次ã®ãããããæãèå³æ·±ãããµã€ã¯ã«ã®äžéšã§ã¯ã æåã®Androidã¢ããªã±ãŒã·ã§ã³ãäœæããŸã ã
ç§ãã¡ãšäžç·ã«...
ããŒã3