mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 12:40:34 +02:00
Examples: Replace lfm-less ComboBox demo by version with lfm form.
This commit is contained in:
parent
718ebb5676
commit
9e67aed7e2
@ -1,48 +1,81 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="12"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<SaveOnlyProjectUnits Value="True"/>
|
<CompatibilityMode Value="True"/>
|
||||||
<LRSInOutputDirectory Value="False"/>
|
|
||||||
</Flags>
|
</Flags>
|
||||||
<MainUnit Value="0"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<Title Value="combobox"/>
|
||||||
|
<Scaled Value="True"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
<UseXPManifest Value="True"/>
|
||||||
|
<XPManifest>
|
||||||
|
<DpiAware Value="True"/>
|
||||||
|
</XPManifest>
|
||||||
|
<Icon Value="0"/>
|
||||||
</General>
|
</General>
|
||||||
<BuildModes Count="1">
|
<BuildModes Count="1">
|
||||||
<Item1 Name="default" Default="True"/>
|
<Item1 Name="Default" Default="True"/>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IgnoreBinaries Value="False"/>
|
<UseFileFilters Value="True"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
|
||||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
|
||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<FormatVersion Value="2"/>
|
||||||
<FormatVersion Value="1"/>
|
|
||||||
</local>
|
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="1">
|
<RequiredPackages Count="1">
|
||||||
<Item1>
|
<Item1>
|
||||||
<PackageName Value="LCL"/>
|
<PackageName Value="LCL"/>
|
||||||
</Item1>
|
</Item1>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="1">
|
<Units Count="2">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="combobox.pp"/>
|
<Filename Value="combobox.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="ComboBox"/>
|
|
||||||
<IsVisibleTab Value="True"/>
|
|
||||||
<TopLine Value="16"/>
|
|
||||||
<CursorPos X="28" Y="32"/>
|
|
||||||
<UsageCount Value="20"/>
|
|
||||||
<Loaded Value="True"/>
|
|
||||||
<LoadedDesigner Value="True"/>
|
|
||||||
</Unit0>
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="comboboxfrm.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<ComponentName Value="Form1"/>
|
||||||
|
<HasResources Value="True"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
|
<UnitName Value="ComboBoxFrm"/>
|
||||||
|
</Unit1>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="11"/>
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="combobox"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Linking>
|
||||||
|
<Options>
|
||||||
|
<Win32>
|
||||||
|
<GraphicApplication Value="True"/>
|
||||||
|
</Win32>
|
||||||
|
</Options>
|
||||||
|
</Linking>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
</CONFIG>
|
</CONFIG>
|
||||||
|
53
examples/combobox.lpr
Normal file
53
examples/combobox.lpr
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
/***************************************************************************
|
||||||
|
combobox.pp
|
||||||
|
-------------
|
||||||
|
Example/test program for combobox usage in lcl
|
||||||
|
|
||||||
|
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This source is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This code is distributed in the hope that it will be useful, but *
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||||
|
* General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* A copy of the GNU General Public License is available on the World *
|
||||||
|
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||||
|
* obtain it by writing to the Free Software Foundation, *
|
||||||
|
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
}
|
||||||
|
program combobox;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
{$IFDEF UNIX}
|
||||||
|
cthreads,
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF HASAMIGA}
|
||||||
|
athreads,
|
||||||
|
{$ENDIF}
|
||||||
|
Interfaces, // this includes the LCL widgetset
|
||||||
|
Forms, ComboBoxFrm
|
||||||
|
{ you can add units after this };
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
|
begin
|
||||||
|
RequireDerivedFormResource:=True;
|
||||||
|
Application.Scaled:=True;
|
||||||
|
Application.Initialize;
|
||||||
|
Application.CreateForm(TForm1, Form1);
|
||||||
|
Application.Run;
|
||||||
|
end.
|
||||||
|
|
@ -1,392 +0,0 @@
|
|||||||
{
|
|
||||||
/***************************************************************************
|
|
||||||
combobox.pp
|
|
||||||
-------------
|
|
||||||
Example/test program for combobox usage in lcl
|
|
||||||
|
|
||||||
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
***************************************************************************
|
|
||||||
* *
|
|
||||||
* This source is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This code is distributed in the hope that it will be useful, but *
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
||||||
* General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* A copy of the GNU General Public License is available on the World *
|
|
||||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
|
||||||
* obtain it by writing to the Free Software Foundation, *
|
|
||||||
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
}
|
|
||||||
program ComboBox;
|
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
|
||||||
|
|
||||||
uses
|
|
||||||
Interfaces, Classes, StdCtrls, Forms, Buttons, Menus, ComCtrls,
|
|
||||||
SysUtils, Extctrls, Controls;
|
|
||||||
|
|
||||||
type
|
|
||||||
TForm1 = class(TFORM)
|
|
||||||
public
|
|
||||||
Label1: TLabel;
|
|
||||||
Label2: TLabel;
|
|
||||||
Label3: TLabel;
|
|
||||||
Button1: TButton;
|
|
||||||
Button2: TButton;
|
|
||||||
Button3: TButton;
|
|
||||||
Button4: TButton;
|
|
||||||
Button5: TButton;
|
|
||||||
Button6: TButton;
|
|
||||||
Button7: TButton;
|
|
||||||
Edit1: TEdit;
|
|
||||||
mnuMain: TMainMenu;
|
|
||||||
itmFileQuit: TMenuItem;
|
|
||||||
itmFile: TMenuItem;
|
|
||||||
ComboBox1: TComboBox;
|
|
||||||
ComboBox2: TComboBox;
|
|
||||||
Memo1: TMemo;
|
|
||||||
constructor Create(AOwner: TComponent); override;
|
|
||||||
procedure LoadMainMenu;
|
|
||||||
procedure FormKill(Sender: TObject);
|
|
||||||
procedure mnuQuitClicked(Sender: TObject);
|
|
||||||
protected
|
|
||||||
procedure Button1CLick(Sender: TObject);
|
|
||||||
procedure Button2CLick(Sender: TObject);
|
|
||||||
procedure Button3CLick(Sender: TObject);
|
|
||||||
procedure Button4CLick(Sender: TObject);
|
|
||||||
procedure Button5CLick(Sender: TObject);
|
|
||||||
procedure Button6CLick(Sender: TObject);
|
|
||||||
procedure Button7CLick(Sender: TObject);
|
|
||||||
procedure ComboOnChange(Sender: TObject);
|
|
||||||
procedure ComboOnClick(Sender: TObject);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
Form1 : TForm1;
|
|
||||||
|
|
||||||
constructor TForm1.Create(AOwner: TComponent);
|
|
||||||
begin
|
|
||||||
inherited CreateNew(AOwner, 1);
|
|
||||||
Caption := 'ComboBox Demo v 0.1';
|
|
||||||
LoadMainMenu;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.Button1Click(Sender : TObject);
|
|
||||||
Begin
|
|
||||||
if assigned (ComboBox1) and assigned (edit1)
|
|
||||||
then ComboBox1.Text := edit1.text;
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button2Click(Sender : TObject);
|
|
||||||
Begin
|
|
||||||
{ if assigned (ComboBox1)
|
|
||||||
then Combobox1.Items.Add ('item ' + IntToStr (comboBox1.Items.Count));
|
|
||||||
if assigned (ComboBox2)
|
|
||||||
then Combobox2.Items.Add ('item ' + IntToStr (comboBox2.Items.Count));}
|
|
||||||
ComboBox1.Items.Add(Edit1.Text);
|
|
||||||
ComboBox2.Items.Add(Edit1.Text);
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button3Click(Sender : TObject);
|
|
||||||
Begin
|
|
||||||
if assigned (ComboBox1) and assigned (edit1)
|
|
||||||
then edit1.Text := ComboBox1.Text;
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button4Click(Sender : TObject);
|
|
||||||
Begin
|
|
||||||
if assigned (ComboBox1)
|
|
||||||
then ComboBox1.Enabled := not ComboBox1.Enabled;
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button5Click(Sender : TObject);
|
|
||||||
var
|
|
||||||
i : integer;
|
|
||||||
Begin
|
|
||||||
if assigned (ComboBox1) then
|
|
||||||
begin
|
|
||||||
i := 0;
|
|
||||||
while i < ComboBox1.Items.Count do
|
|
||||||
begin
|
|
||||||
if assigned (Memo1)
|
|
||||||
then Memo1.Lines.Add (ComboBox1.Items[i]);
|
|
||||||
inc (i);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button6Click(Sender : TObject);
|
|
||||||
var
|
|
||||||
s : shortstring;
|
|
||||||
Begin
|
|
||||||
if assigned (ComboBox1) then
|
|
||||||
begin
|
|
||||||
s := Format ('%x', [ComboBox1.ItemIndex]);
|
|
||||||
if assigned (Memo1)
|
|
||||||
then Memo1.Lines.Add (s);
|
|
||||||
end;
|
|
||||||
End;
|
|
||||||
|
|
||||||
procedure TForm1.Button7Click(Sender : TObject);
|
|
||||||
begin
|
|
||||||
Edit1.SelectAll;
|
|
||||||
ComboBox1.SelectAll;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TForm1.ComboOnChange (Sender:TObject);
|
|
||||||
var
|
|
||||||
s : shortstring;
|
|
||||||
begin
|
|
||||||
if sender is TEdit
|
|
||||||
then s := TCOntrol(Sender).name+':TEdit - '
|
|
||||||
else if sender is TComboBox
|
|
||||||
then s := TControl(Sender).name+':TComboBox - '
|
|
||||||
else
|
|
||||||
s := 'UNKNOWN';
|
|
||||||
if assigned (Memo1)
|
|
||||||
then Memo1.Lines.Add (s + 'ONChange');
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.ComboOnClick (Sender:TObject);
|
|
||||||
begin
|
|
||||||
if assigned (Memo1)
|
|
||||||
then Memo1.Lines.Add ('ONClick');
|
|
||||||
end;
|
|
||||||
{------------------------------------------------------------------------------}
|
|
||||||
|
|
||||||
procedure TForm1.FormKill(Sender : TObject);
|
|
||||||
Begin
|
|
||||||
|
|
||||||
End;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------}
|
|
||||||
procedure TForm1.LoadMainMenu;
|
|
||||||
|
|
||||||
begin
|
|
||||||
OnDestroy := @FormKill;
|
|
||||||
|
|
||||||
{ set the height and width }
|
|
||||||
Height := 350;
|
|
||||||
Width := 700;
|
|
||||||
|
|
||||||
{ Create 2 buttons inside the groupbox }
|
|
||||||
Button2 := TButton.Create(Self);
|
|
||||||
Button2.Parent := Self;
|
|
||||||
Button2.Left := 50;
|
|
||||||
Button2.Top := 40;
|
|
||||||
Button2.Width := 120;
|
|
||||||
Button2.Height := 30;
|
|
||||||
Button2.Show;
|
|
||||||
Button2.Caption := 'Add item';
|
|
||||||
Button2.OnClick := @Button2Click;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Button1 := TButton.Create(Self);
|
|
||||||
Button1.Parent := Self;
|
|
||||||
Button1.Left := 50;
|
|
||||||
Button1.Top := 80;
|
|
||||||
Button1.Width := 120;
|
|
||||||
Button1.Height := 30;
|
|
||||||
Button1.Show;
|
|
||||||
Button1.Caption := 'Edit->Combo';
|
|
||||||
Button1.OnClick := @Button1Click;
|
|
||||||
|
|
||||||
|
|
||||||
{ Create 2 more buttons outside the groupbox }
|
|
||||||
Button3 := TButton.Create(Self);
|
|
||||||
Button3.Parent := Self;
|
|
||||||
Button3.Left := 50;
|
|
||||||
Button3.Top := 120;
|
|
||||||
Button3.Width := 120;
|
|
||||||
Button3.Height := 30;
|
|
||||||
Button3.Show;
|
|
||||||
Button3.Caption := 'Combo->Edit';
|
|
||||||
Button3.OnClick := @Button3Click;
|
|
||||||
|
|
||||||
|
|
||||||
Button4 := TButton.Create(Self);
|
|
||||||
Button4.Parent := Self;
|
|
||||||
Button4.Left := 50;
|
|
||||||
Button4.Top := 160;
|
|
||||||
Button4.Width := 120;
|
|
||||||
Button4.Height := 30;
|
|
||||||
Button4.Show;
|
|
||||||
Button4.Caption := 'Enabled On/Off';
|
|
||||||
Button4.OnClick := @Button4Click;
|
|
||||||
|
|
||||||
Button5 := TButton.Create(Self);
|
|
||||||
Button5.Parent := Self;
|
|
||||||
Button5.Left := 50;
|
|
||||||
Button5.Top := 200;
|
|
||||||
Button5.Width := 120;
|
|
||||||
Button5.Height := 30;
|
|
||||||
Button5.Show;
|
|
||||||
Button5.Caption := 'Dump';
|
|
||||||
Button5.OnClick := @Button5Click;
|
|
||||||
|
|
||||||
Button6 := TButton.Create(Self);
|
|
||||||
Button6.Parent := Self;
|
|
||||||
Button6.Left := 50;
|
|
||||||
Button6.Top := 240;
|
|
||||||
Button6.Width := 120;
|
|
||||||
Button6.Height := 30;
|
|
||||||
Button6.Show;
|
|
||||||
Button6.Caption := 'Index ?';
|
|
||||||
Button6.OnClick := @Button6Click;
|
|
||||||
|
|
||||||
Button7 := TButton.Create(Self);
|
|
||||||
Button7.Parent := Self;
|
|
||||||
Button7.Left := 50;
|
|
||||||
Button7.Top := 280;
|
|
||||||
Button7.Width := 120;
|
|
||||||
Button7.Height := 30;
|
|
||||||
Button7.Show;
|
|
||||||
Button7.Caption := 'Select All';
|
|
||||||
Button7.OnClick := @Button7Click;
|
|
||||||
|
|
||||||
|
|
||||||
{ Create a label for the edit field }
|
|
||||||
label1 := TLabel.Create(Self);
|
|
||||||
label1.Parent := self;
|
|
||||||
label1.top := 50;
|
|
||||||
label1.left := 320;
|
|
||||||
label1.Height := 20;
|
|
||||||
label1.Width := 130;
|
|
||||||
label1.Show;
|
|
||||||
label1.Caption := 'TEdit :';
|
|
||||||
|
|
||||||
|
|
||||||
Edit1 := TEdit.Create (self);
|
|
||||||
with Edit1 do
|
|
||||||
begin
|
|
||||||
Parent := self;
|
|
||||||
Left := 500;
|
|
||||||
Top := 50;
|
|
||||||
Width := 70;
|
|
||||||
Height := 20;
|
|
||||||
OnChange := @ComboOnChange;
|
|
||||||
OnClick := @ComboOnClick;
|
|
||||||
Name := 'Edit1';
|
|
||||||
Show;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ Create a label for the 1st combobox }
|
|
||||||
label2 := TLabel.Create(Self);
|
|
||||||
label2.Parent := self;
|
|
||||||
label2.top := 100;
|
|
||||||
label2.left := 320;
|
|
||||||
label2.Height := 20;
|
|
||||||
label2.Width := 130;
|
|
||||||
label2.Enabled:= true;
|
|
||||||
label2.Show;
|
|
||||||
label2.Caption := 'Combo (unsorted)';
|
|
||||||
label2.Enabled:= true;
|
|
||||||
|
|
||||||
|
|
||||||
{ Create the menu now }
|
|
||||||
{ WARNING: If you do it after creation of the combo, the menu will not
|
|
||||||
appear. Reason is unknown by now!!!!!!}
|
|
||||||
mnuMain := TMainMenu.Create(Self);
|
|
||||||
Menu := mnuMain;
|
|
||||||
itmFile := TMenuItem.Create(Self);
|
|
||||||
itmFile.Caption := '&File';
|
|
||||||
mnuMain.Items.Add(itmFile);
|
|
||||||
itmFileQuit := TMenuItem.Create(Self);
|
|
||||||
itmFileQuit.Caption := '&Quit';
|
|
||||||
itmFileQuit.OnClick := @mnuQuitClicked;
|
|
||||||
itmFile.Add(itmFileQuit);
|
|
||||||
|
|
||||||
ComboBox1 := TComboBox.Create (self);
|
|
||||||
with ComboBox1 do
|
|
||||||
begin
|
|
||||||
Parent := self;
|
|
||||||
Left := 500;
|
|
||||||
Top := 100;
|
|
||||||
Width := 170;
|
|
||||||
Height := 20;
|
|
||||||
Style := csDropDown;
|
|
||||||
Items.Add ('wohhh!');
|
|
||||||
Items.Add ('22222!');
|
|
||||||
ItemIndex := 1;
|
|
||||||
Items.Add ('33333!');
|
|
||||||
Items.Add ('abcde!');
|
|
||||||
OnChange := @ComboOnChange;
|
|
||||||
OnClick := @ComboOnClick;
|
|
||||||
Name := 'ComboBox1';
|
|
||||||
Show;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ Create a label for the 2nd combobox }
|
|
||||||
label3 := TLabel.Create(Self);
|
|
||||||
label3.Parent := self;
|
|
||||||
label3.top := 150;
|
|
||||||
label3.left := 320;
|
|
||||||
label3.Height := 20;
|
|
||||||
label3.Width := 130;
|
|
||||||
label3.Show;
|
|
||||||
label3.Caption := 'Combo (sorted)';
|
|
||||||
|
|
||||||
|
|
||||||
ComboBox2 := TComboBox.Create (self);
|
|
||||||
with ComboBox2 do
|
|
||||||
begin
|
|
||||||
Parent := self;
|
|
||||||
Left := 500;
|
|
||||||
Top := 150;
|
|
||||||
Width := 170;
|
|
||||||
Height := 20;
|
|
||||||
Style := csDropDownList;
|
|
||||||
Items.Add ('wohhh!');
|
|
||||||
Items.Add ('22222!');
|
|
||||||
ItemIndex := 1;
|
|
||||||
Items.Add ('33333!');
|
|
||||||
Items.Add ('abcde!');
|
|
||||||
Name := 'ComboBox2';
|
|
||||||
OnChange := @ComboOnChange;
|
|
||||||
OnClick := @ComboOnClick;
|
|
||||||
Sorted := true;
|
|
||||||
Show;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
Memo1 := TMemo.Create(Self);
|
|
||||||
with Memo1 do
|
|
||||||
begin
|
|
||||||
Parent := Self;
|
|
||||||
Scrollbars := ssBoth;
|
|
||||||
Left := 200;
|
|
||||||
Top := 200;
|
|
||||||
Width := 335;
|
|
||||||
Height := 155;
|
|
||||||
Show;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------}
|
|
||||||
procedure TForm1.mnuQuitClicked(Sender : TObject);
|
|
||||||
begin
|
|
||||||
Close;
|
|
||||||
end;
|
|
||||||
{------------------------------------------------------------------------------}
|
|
||||||
|
|
||||||
begin
|
|
||||||
Application.Initialize; { calls InitProcedure which starts up GTK }
|
|
||||||
Application.CreateForm(TForm1, Form1);
|
|
||||||
Application.Run;
|
|
||||||
end.
|
|
||||||
|
|
160
examples/comboboxfrm.lfm
Normal file
160
examples/comboboxfrm.lfm
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
object Form1: TForm1
|
||||||
|
Left = 270
|
||||||
|
Height = 423
|
||||||
|
Top = 131
|
||||||
|
Width = 714
|
||||||
|
Caption = 'ComboBox Demo v0.2'
|
||||||
|
ClientHeight = 403
|
||||||
|
ClientWidth = 714
|
||||||
|
Menu = mnuMain
|
||||||
|
LCLVersion = '2.3.0.0'
|
||||||
|
object Button2: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 40
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Add item'
|
||||||
|
OnClick = Button2Click
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object Button1: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 80
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Edit -> Combo'
|
||||||
|
OnClick = Button1Click
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object Button3: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 120
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Combo -> Edit'
|
||||||
|
OnClick = Button3Click
|
||||||
|
TabOrder = 2
|
||||||
|
end
|
||||||
|
object Button4: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 160
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Enabled On/Off'
|
||||||
|
OnClick = Button4Click
|
||||||
|
TabOrder = 3
|
||||||
|
end
|
||||||
|
object Button5: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 200
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Dump'
|
||||||
|
OnClick = Button5Click
|
||||||
|
TabOrder = 4
|
||||||
|
end
|
||||||
|
object Button6: TButton
|
||||||
|
Left = 50
|
||||||
|
Height = 30
|
||||||
|
Top = 240
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Index ?'
|
||||||
|
OnClick = Button6Click
|
||||||
|
TabOrder = 5
|
||||||
|
end
|
||||||
|
object Button7: TButton
|
||||||
|
Left = 49
|
||||||
|
Height = 30
|
||||||
|
Top = 280
|
||||||
|
Width = 120
|
||||||
|
Caption = 'Select All'
|
||||||
|
OnClick = Button7Click
|
||||||
|
TabOrder = 6
|
||||||
|
end
|
||||||
|
object Label1: TLabel
|
||||||
|
Left = 320
|
||||||
|
Height = 15
|
||||||
|
Top = 50
|
||||||
|
Width = 29
|
||||||
|
Caption = 'TEdit:'
|
||||||
|
end
|
||||||
|
object Edit1: TEdit
|
||||||
|
Left = 500
|
||||||
|
Height = 23
|
||||||
|
Top = 50
|
||||||
|
Width = 70
|
||||||
|
OnChange = ComboOnChange
|
||||||
|
OnClick = ComboOnClick
|
||||||
|
TabOrder = 7
|
||||||
|
Text = 'Edit1'
|
||||||
|
end
|
||||||
|
object Label2: TLabel
|
||||||
|
Left = 320
|
||||||
|
Height = 15
|
||||||
|
Top = 100
|
||||||
|
Width = 101
|
||||||
|
Caption = 'Combo (unsorted):'
|
||||||
|
end
|
||||||
|
object ComboBox1: TComboBox
|
||||||
|
Left = 500
|
||||||
|
Height = 23
|
||||||
|
Top = 100
|
||||||
|
Width = 170
|
||||||
|
ItemHeight = 15
|
||||||
|
ItemIndex = 1
|
||||||
|
Items.Strings = (
|
||||||
|
'wohh!'
|
||||||
|
'22222!'
|
||||||
|
'33333!'
|
||||||
|
'abcde!'
|
||||||
|
)
|
||||||
|
OnChange = ComboOnChange
|
||||||
|
OnClick = ComboOnClick
|
||||||
|
TabOrder = 8
|
||||||
|
Text = '22222!'
|
||||||
|
end
|
||||||
|
object Label3: TLabel
|
||||||
|
Left = 320
|
||||||
|
Height = 15
|
||||||
|
Top = 150
|
||||||
|
Width = 87
|
||||||
|
Caption = 'Combo (sorted):'
|
||||||
|
end
|
||||||
|
object ComboBox2: TComboBox
|
||||||
|
Left = 500
|
||||||
|
Height = 23
|
||||||
|
Top = 150
|
||||||
|
Width = 170
|
||||||
|
ItemHeight = 15
|
||||||
|
ItemIndex = 1
|
||||||
|
Items.Strings = (
|
||||||
|
'22222!'
|
||||||
|
'33333!'
|
||||||
|
'abcde!'
|
||||||
|
'wohhh!'
|
||||||
|
)
|
||||||
|
Sorted = True
|
||||||
|
Style = csDropDownList
|
||||||
|
TabOrder = 9
|
||||||
|
Text = '33333!'
|
||||||
|
end
|
||||||
|
object Memo1: TMemo
|
||||||
|
Left = 235
|
||||||
|
Height = 176
|
||||||
|
Top = 200
|
||||||
|
Width = 435
|
||||||
|
ScrollBars = ssBoth
|
||||||
|
TabOrder = 10
|
||||||
|
end
|
||||||
|
object mnuMain: TMainMenu
|
||||||
|
Left = 242
|
||||||
|
Top = 75
|
||||||
|
object itmFile: TMenuItem
|
||||||
|
Caption = '&File'
|
||||||
|
object itmFileQuit: TMenuItem
|
||||||
|
Caption = '&Quit'
|
||||||
|
OnClick = itmFileQuitClick
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
141
examples/comboboxfrm.pas
Normal file
141
examples/comboboxfrm.pas
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
unit ComboBoxFrm;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
TForm1 = class(TForm)
|
||||||
|
Button1: TButton;
|
||||||
|
Button2: TButton;
|
||||||
|
Button3: TButton;
|
||||||
|
Button4: TButton;
|
||||||
|
Button5: TButton;
|
||||||
|
Button6: TButton;
|
||||||
|
Button7: TButton;
|
||||||
|
ComboBox1: TComboBox;
|
||||||
|
ComboBox2: TComboBox;
|
||||||
|
Edit1: TEdit;
|
||||||
|
Label1: TLabel;
|
||||||
|
Label2: TLabel;
|
||||||
|
Label3: TLabel;
|
||||||
|
itmFile: TMenuItem;
|
||||||
|
itmFileQuit: TMenuItem;
|
||||||
|
mnuMain: TMainMenu;
|
||||||
|
Memo1: TMemo;
|
||||||
|
procedure Button1Click(Sender: TObject);
|
||||||
|
procedure Button2Click(Sender: TObject);
|
||||||
|
procedure Button3Click(Sender: TObject);
|
||||||
|
procedure Button4Click(Sender: TObject);
|
||||||
|
procedure Button5Click(Sender: TObject);
|
||||||
|
procedure Button6Click(Sender: TObject);
|
||||||
|
procedure Button7Click(Sender: TObject);
|
||||||
|
procedure ComboOnChange(Sender: TObject);
|
||||||
|
procedure ComboOnClick(Sender: TObject);
|
||||||
|
procedure itmFileQuitClick(Sender: TObject);
|
||||||
|
private
|
||||||
|
|
||||||
|
public
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Form1: TForm1;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
procedure TForm1.Button1Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if Assigned(ComboBox1) and Assigned(Edit1) then
|
||||||
|
ComboBox1.Text := Edit1.Text;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button2Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
ComboBox1.Items.Add(Edit1.Text);
|
||||||
|
ComboBox2.Items.Add(Edit1.Text);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button3Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if Assigned(ComboBox1) and Assigned(Edit1) then
|
||||||
|
Edit1.Text := ComboBox1.Text;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button4Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if Assigned(ComboBox1) then
|
||||||
|
ComboBox1.Enabled := not ComboBox1.Enabled;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button5Click(Sender: TObject);
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
if Assigned(ComboBox1) then
|
||||||
|
begin
|
||||||
|
i := 0;
|
||||||
|
while i < ComboBox1.Items.Count do
|
||||||
|
begin
|
||||||
|
if Assigned(Memo1) then
|
||||||
|
Memo1.Lines.Add(ComboBox1.Items[i]);
|
||||||
|
inc (i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button6Click(Sender: TObject);
|
||||||
|
var
|
||||||
|
s: string;
|
||||||
|
begin
|
||||||
|
if Assigned(ComboBox1) then
|
||||||
|
begin
|
||||||
|
s := Format ('%x', [ComboBox1.ItemIndex]);
|
||||||
|
if Assigned(Memo1) then
|
||||||
|
Memo1.Lines.Add (s);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button7Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Edit1.SelectAll;
|
||||||
|
ComboBox1.SelectAll;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.ComboOnChange(Sender: TObject);
|
||||||
|
var
|
||||||
|
s: string;
|
||||||
|
begin
|
||||||
|
if Sender is TEdit then
|
||||||
|
s := TControl(Sender).Name + ':TEdit - '
|
||||||
|
else if Sender is TComboBox then
|
||||||
|
s := TControl(Sender).Name + ':TComboBox - '
|
||||||
|
else
|
||||||
|
s := 'UNKNOWN';
|
||||||
|
if Assigned(Memo1) then
|
||||||
|
Memo1.Lines.Add(s + 'OnChange');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.ComboOnClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if Assigned(Memo1) then
|
||||||
|
Memo1.Lines.Add('OnClick');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.itmFileQuitClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Close;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user