Topic: new design by code

hello all


I like the code and I am trying to make a project using the code but I need some experience from you

i created new design

help [1]

how can i search by code for example


procedure Form1_ComboBox1_OnChange (Sender: TObject; Action: string);
begin
      // here how can i search by code
    // SQLExecute(SELECT * FROM Studentd VALUES ("'+form1.ComboBox1.Text+'")');
end;

thanks for help

Post's attachments

Attachment icon newdesign.rar 343.84 kb, 307 downloads since 2020-12-06 

2 (edited by brian.zaballa 2020-12-07 01:59:01)

Re: new design by code

Have you tried the search feature of MVD? Searching it by code can be done but will require you additional code in populating the Grid so I suggest you use the search of MVD

Post's attachments

Attachment icon newdesign2.zip 834.78 kb, 333 downloads since 2020-12-07 

brian

Re: new design by code

hello brian.zaballa

thanks for advance

please can you write search code for one edit box  without  use the search of MVD and i will complete the other

thanks for help

Re: new design by code

kofa,
Although I do not agree with your design, I put in script to filter your tablegrid. I wasn't sure if you wanted OR logic or AND logic in your searches so each are independent filters. I did Saff combobox and Name edit field. In my opinion I think you are over scripting in your project, but I do not know what the big picture is for your application.


Why do you fill the search fields when you click on a row in the tablegrid?

Post's attachments

Attachment icon Kofa Search.zip 676.17 kb, 322 downloads since 2020-12-08 

5 (edited by kofa 2020-12-08 07:48:07)

Re: new design by code

hello ehwagner

thank you very very much

can you please check the code error in file

thanks for help

Post's attachments

Attachment icon newdesign3.rar 355.17 kb, 308 downloads since 2020-12-08 

Re: new design by code

What code error? I am not getting any errors.

Re: new design by code

hello ehwagner

when i type in a Name textbox

thanks for your time and help

Re: new design by code

kofa,
You cannot use SqlExecute to populate a tablegrid like you want. If you are not going to use the MVD built-in Search feature, then you either need a button with action of Sql Query, or dbSql script or dbFilter script. Take a look at the project I posted in this thread for a sample of dbFilter script.

9 (edited by kofa 2020-12-09 08:39:02)

Re: new design by code

hello ehwagner

At first accept my apologies because I am still a beginner. Second, I studied your code in the previous example

And I successfully searched, added and deleted, but I failed in the edit button,

so can you help me with this problem

thanks for help

Post's attachments

Attachment icon Edit_Button.rar 350.86 kb, 294 downloads since 2020-12-09 

Re: new design by code

kofa,
You really should create another form to do your ADDs and EDITs. You can't use the fields on Form1 for both searching and updating. Create FORM2 or whatever you want to call it, then place all your fields on there, connect them to the table in the database. Then place a SAVE button on the form and include all the fields in the SAVE action. On FORM1 change the Add and Edit buttons to point to your second form. All this is done without any scripts. You are trying to do way too much on one form. You do not need any of the script to populate the Search fields in Form1 when you click on a tablegrid row. It is misleading to the user.

Re: new design by code

hello ehwagner

thanks for advance

what is the error in this code



procedure Edit_function_button (Sender: TObject; Action: string);
begin

Form1.Table.dbsqlexecute('UPDATE Students SET Saff = "'+Form1.Edit1.Text+'",Fasl= "'+Form1.Edit2.Text+'",Name= "'+Form1.Name_txt.Text+'",Nationality= "'+Form1.Edit3.Text+'",Phone= "'+Form1.Phone_txt.Text+'",Gheyab= "'+Form1.Gheyab_txt.Text+'",Takheer= "'+Form1.Takheer_txt.Text+'",Health= "'+Form1.Health_txt.Text+'",Notes1= "'+Form1.Notes1_txt.Text+'",Notes2= "'+Form1.Notes2_txt.Text+'" WHERE id= "'+Form1.Edit4.Text+'" ;');

 Form1.Table.dbUpdate;

 end;

thanks for help

Re: new design by code

hello all

excuse me for a lot of ask help

i happy to learn a new functions every day

how can i get full image path after DBImage1 click which opens file dialog

thanks for help

Re: new design by code

procedure Edit_function_button (Sender: TObject; Action: string);
begin

Form1.Table.dbsqlexecute('UPDATE Students SET Saff = "'+Form1.Edit1.Text+'",Fasl= "'+Form1.Edit2.Text+'",Name= "'+Form1.Name_txt.Text+'",Nationality= "'+Form1.Edit3.Text+'",Phone= "'+Form1.Phone_txt.Text+'",Gheyab= "'+Form1.Gheyab_txt.Text+'",Takheer= "'+Form1.Takheer_txt.Text+'",Health= "'+Form1.Health_txt.Text+'",Notes1= "'+Form1.Notes1_txt.Text+'",Notes2= "'+Form1.Notes2_txt.Text+'" WHERE id= "'+Form1.Edit4.Text+'" ;');

 Form1.Table.dbUpdate;

 end;

Form1.Table.dbsqlexecute is not the correct function. This is used to populate a tablegrid. You want to use SqlExecute('...'). However, you are putting in script which MVD will do for you without script.

Since you are relatively new to MVD, may I give you a little advice and it is exactly what I did in the beginning. I studied the examples/tutorials on this website until I understood how MVD works and what it does for you automatically with its Actions and form flow. I built very elementary projects to learn from. It seems like you are trying to go right into scripting without learning the basics of MVD. Believe me, you will have plenty of opportunities to interject scripting as you advance your projects. If I am wrong on this, my apology. But I just want to guide you in the right direction as a newbie.

Re: new design by code

hello ehwagner


My respect and appreciation to you

thanks for advance

Re: new design by code

hello all

i want to make message box with ok and cancel

i tired to solve this code

procedure Form1_Button6_OnClick(Sender: TObject);
var
  buttonSelected : Integer;
begin

  buttonSelected := messagedlg('Confirmation',mtError,mbOKCancel, 0);
  if buttonSelected = mrOK     then ShowMessage('OK pressed');
  if buttonSelected = mrCancel then ShowMessage('Cancel pressed');
end;

can you help me

thanks for help

Re: new design by code

kofa wrote:

hello all

i want to make message box with ok and cancel

i tired to solve this code

procedure Form1_Button6_OnClick(Sender: TObject);
var
  buttonSelected : Integer;
begin

  buttonSelected := messagedlg('Confirmation',mtError,mbOKCancel, 0);
  if buttonSelected = mrOK     then ShowMessage('OK pressed');
  if buttonSelected = mrCancel then ShowMessage('Cancel pressed');
end;

can you help me

thanks for help

you can try this custom function

//Comfirm massages with "Yes or No"
function Confirm(msg: String; ICON: Integer=MB_ICONQUESTION; title:String='Confirm'): boolean;
begin
    result := IDYES = MessageBox(msg, 'App Name: '+title, MB_YESNO+ICON);
end;

to use it,

if Confirm('Are you sure?') then begin
    showmessage('ok');
end else begin
   showmessage('cancel');
end; 
brian

Re: new design by code

hello brian.zaballa

thanks for your replay

but there is an error ( List index out of bounds(1) )

can you solve it please

thanks for help

18 (edited by CDB 2020-12-12 10:43:55)

Re: new design by code

Hello Kofa and Brian,


You could try this:


procedure Form1_Button6_OnClick(Sender: TObject);
var
  buttonSelected : Integer;
begin

  buttonSelected := messagedlg('Confirmation',mtError, mbOK+mbCancel, 0);

  if buttonSelected = mrOK   then 
  
       ShowMessage('OK pressed') 
 else  
      buttonSelected = mrCancel then ShowMessage('Cancel pressed');
 end;
end;
On a clear disk you can seek forever

Re: new design by code

thanks CDB

this works

procedure Form1_Button7_OnClick(Sender: TObject ; Action: Integer ) ;
var
  buttonSelected : Integer;
begin

  buttonSelected := messagedlg('Confirmation',mtError, mbOK+mbCancel, 0);

  if buttonSelected = mrOK   then
     begin
       ShowMessage('OK pressed')
       end
 else if

      buttonSelected = mrCancel then
       begin
      ShowMessage('Cancel pressed');
 end;
end;

Re: new design by code

hello all

what is the code to change table direction to right to left

for example  Form1.tablegrid.SetLayout(LAYOUT_RTL);

thanks for help

21 (edited by kofa 2020-12-13 08:40:28)

Re: new design by code

hello all

i tired to use Trim function

form1.Edit1.Text:=Trim(Form1.ComboBox1.Text);

and tired to use StringReplace

form1.Edit1.Text:=StringReplace(Form1.ComboBox1.Text, '', '',[rfReplaceAll]);

can you help me please

thanks for all

Re: new design by code

hello all

it is possible to use custom font in my application folder not in windows font  for examble

Form1.ComboBox4.Font :=  applicationfolder/fonts/myfont.ttf ;

thanks for help

Re: new design by code

Hello Kofa

Can this help you ?

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.GridEmployees.Font := LoadFont;
end;

procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var    FontDialog: TFontDialog;
begin
    FontDialog := TFontDialog.Create(Form1);
    FontDialog.Font := Form1.GridEmployees.Font;
    if FontDialog.Execute then
    begin
        Form1.GridEmployees.Font:= FontDialog.Font;
        Form1.GridEmployees.dbUpdate;
        SaveFont(Form1.GridEmployees.Font);
    end;
end;

procedure SaveFont(Font: TFont);
var   reg: TRegistry;
begin
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;

     if reg.OpenKey('software\YourProjectName', true) then
     begin
          Reg.WriteString('Font.Name', Font.Name);
          Reg.WriteInteger('Font.Size', Font.Size);
          Reg.WriteBool('Font.Style.fsBold', fsBold in [Font.Style]);
          Reg.WriteBool('Font.Style.fsItalic', fsItalic in [Font.Style]);
          Reg.WriteBool('Font.Style.fsUnderline', fsUnderline in [Font.Style]);
          Reg.WriteBool('Font.Style.fsStrikeOut', fsStrikeOut in [Font.Style]);
          reg.CloseKey;
     end;

     reg.Free;
end;


function LoadFont: TFont;
var   reg: TRegistry;
begin
     result := TFont.Create;
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;

     if reg.OpenKey('software\YourProjectName', true) then
     begin
          if reg.ValueExists('Font.Name') then result.Name := Reg.ReadString('Font.Name');
          if reg.ValueExists('Font.Size') then result.Size := Reg.ReadInteger('Font.Size');

          if reg.ValueExists('Font.Style.fsBold') then
              if Reg.ReadBool('Font.Style.fsBold') then result.Style := result.Style + fsBold;
          if reg.ValueExists('Font.Style.fsItalic') then
              if Reg.ReadBool('Font.Style.fsItalic') then result.Style := result.Style + fsItalic;
          if reg.ValueExists('Font.Style.fsUnderline') then
              if Reg.ReadBool('Font.Style.fsUnderline') then result.Style := result.Style + fsUnderline;
          if reg.ValueExists('Font.Style.fsStrikeOut') then
              if Reg.ReadBool('Font.Style.fsStrikeOut') then result.Style := result.Style + fsStrikeOut;

          reg.CloseKey;
     end;

     reg.Free;

JB

Re: new design by code

hello jean.brezhonek

it take a while to understand it

i will study it and try

excuse me i am still beginner

thank you very much

Re: new design by code

Hello kofa

The advantage of this code allows the user to have the font of his choice on his PC without having to modify his font each time by going to look for another one on the right or on the left.

JB