delphi - wrong database name showing on my main form -


it seems cant work properly. somehow messing "if then" sequence.

i got on login form:

procedure tlogin_form.advglowbutton1click(sender: tobject); begin   data_module.login.active:=false;   data_module.login.sql.clear;   data_module.login.sql.text:= 'select [loc_id],[user],[password],[access] users [user] ='+quotedstr(cxlookupcombobox1.text) +' , [password]='+quotedstr(cxtextedit1.text);   data_module.login.open;    if data_module.login.fieldbyname('password').asstring<>''   begin     if data_module.login.fieldbyname('loc_id').asinteger = 1       data_module.acrdatabase1.databasefilename := extractfilepath(application.exename)+ '..\database\db1.adb';     data_module.acrdatabase1.databasename :='database1';     data_module.acrdatabase1.connected:=true;     if data_module.login.fieldbyname('loc_id').asinteger = 2       data_module.acrdatabase1.databasefilename := extractfilepath(application.exename)+ '..\database\db2.adb';     data_module.acrdatabase1.databasename :='database2';     data_module.acrdatabase1.connected:=true;     modalresult := mrok   end   else     modalresult := mrnone;    cxtextedit1.clear;   dxstatusbar1.panels[1].text :='wrong password !';   cxtextedit1.setfocus; end; 

modalresult ok shows main form.

just check database name if shows right....

procedure tmain_form.formshow(sender: tobject); begin   if data_module.acrdatabase1.connected     advofficestatusbar1.panels[0].text := data_module.acrdatabase1.databasename   else     advofficestatusbar1.panels[0].text :=''; end; 

somehow, end wrong database name on mainform. doing wrong ? tried various ways failed.

also wondering if "case" statement can used here this:

case data_module.login.fieldbyname('loc_id').value of 1:begin

since have 5 databases choose ?

we use begin end blocks when write multiple lines of code.

procedure tlogin_form.advglowbutton1click(sender: tobject); begin   data_module.login.active:=false;   data_module.login.sql.clear;   data_module.login.sql.text:= 'select [loc_id],[user],[password],[access]     users [user] ='+quotedstr(cxlookupcombobox1.text) +' ,     [password]='+quotedstr(cxtextedit1.text);   data_module.login.open;    if data_module.login.fieldbyname('password').asstring<>''   begin     if data_module.login.fieldbyname('loc_id').asinteger = 1       begin         data_module.acrdatabase1.databasefilename :=     extractfilepath(application.exename)+ '..\database\db1.adb';         data_module.acrdatabase1.databasename :='database1';       end     else if data_module.login.fieldbyname('loc_id').asinteger = 2       begin         data_module.acrdatabase1.databasefilename :=     extractfilepath(application.exename)+ '..\database\db2.adb';         data_module.acrdatabase1.databasename :='database2';       end;      data_module.acrdatabase1.connected:=true;     modalresult := mrok   end   else     modalresult := mrnone;    cxtextedit1.clear;   dxstatusbar1.panels[1].text :='wrong password !';   cxtextedit1.setfocus; end; 

yes, can use case statement that.

with case of statement

  case data_module.login.fieldbyname('loc_id').asinteger of     1:begin       data_module.acrdatabase1.databasefilename :=     extractfilepath(application.exename)+ '..\database\db1.adb';       data_module.acrdatabase1.databasename :='database1';     end;     2:begin       data_module.acrdatabase1.databasefilename :=     extractfilepath(application.exename)+ '..\database\db2.adb';       data_module.acrdatabase1.databasename :='database2';     end;   end; 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -