Topic: Example Basic Change Caption,ICON button By Database
Compile MVD 4.6 +++
Knowledge In This Example
- button can change caption or icon from value database
- can apply save setting insert to database and load value quick time program open
Happy Everybody MVD!
Screen Shot
Open Code
var
listview : Tlistview ;
ImageList: TImageList;
i : integer ;
sl: TStringList;
ci : integer ;
procedure Form1_TableGrid1_OnChange (Sender: TObject);
var
ti : integer ;
begin
For ti := 0 to Form1.controlCount -1 do
Begin
IF (Form1.controls[ti] is TButton) then
Begin
TButton(Form1.Controls[ti]).caption :=
SQLExecute('SELECT caption from button where ci = '+IntToStr(ti));
TButton(Form1.Controls[ti]).images := ImageList ;
TButton(Form1.Controls[ti]).imageindex :=
SQLExecute('SELECT imageindex from button where ci = '+IntToStr(ti));
End;
End;
end;
begin
ImageList:=TImageList.Create(Form1);
ImageList.Masked:=false;
ImageList.ColorDepth:=cd32bit;
ImageList.Width := 16;
ImageList.Height := 16;
sl := TStringList.Create;
sl.Text := GetFilesList(ExtractFilePath(Application.ExeName)+'icon','*.png');
For i := 0 To sl.count-1 Do
Begin
ImageList.AddPng(sl[i]);
end ;
listview := Tlistview.Create(Form1);
listview.Parent := Form1.Panel1;
listview.Align := alClient;
listview.StateImages := ImageList;
listview.smallimages := ImageList;
listview.Largeimages := ImageList;
listview.GridLines := True;
listview.viewStyle := vsreport ;
listview.Columns.add();
listview.Columns.add();
listview.Columns[0].caption := 'Icon : Name' ;
listview.Columns[1].caption := 'Imageindex' ;
listview.Columns[0].AutoSize := True ;
listview.Columns[1].AutoSize := True ;
For i := 0 To sl.count-1 Do
begin
with ListView.Items.Add do
begin
ImageIndex := i;
Caption := ' : '+replacestr(sl[i],ExtractFilePath(Application.ExeName)+'icon\','');
SubItems.Add(IntToStr(i));
end;
end;
For ci := 0 to Form1.controlCount -1 do
if (Form1.controls[ci] is TButton) then
begin
SQLExecute('INSERT INTO button(name,caption,imageindex,ci) values ('+
'"'+TButton(Form1.Controls[ci]).name+'",'+
'"'+TButton(Form1.Controls[ci]).caption+'",'+
'"'+IntToStr(TButton(Form1.Controls[ci]).imageindex)+'",'+
'"'+IntToStr(ci)+'" );');
End;
end.
Easy For Beginner Student For Me