mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-08 09:20:49 +02:00
started TDBComboBox
git-svn-id: trunk@4638 -
This commit is contained in:
parent
5e5c1122a7
commit
f7dcbba69f
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -807,6 +807,7 @@ lcl/include/customradiogroup.inc svneol=native#text/pascal
|
|||||||
lcl/include/customstatictext.inc svneol=native#text/pascal
|
lcl/include/customstatictext.inc svneol=native#text/pascal
|
||||||
lcl/include/customupdown.inc svneol=native#text/pascal
|
lcl/include/customupdown.inc svneol=native#text/pascal
|
||||||
lcl/include/dbcheckbox.inc svneol=native#text/pascal
|
lcl/include/dbcheckbox.inc svneol=native#text/pascal
|
||||||
|
lcl/include/dbcombobox.inc svneol=native#text/pascal
|
||||||
lcl/include/dbedit.inc svneol=native#text/pascal
|
lcl/include/dbedit.inc svneol=native#text/pascal
|
||||||
lcl/include/dblistbox.inc svneol=native#text/pascal
|
lcl/include/dblistbox.inc svneol=native#text/pascal
|
||||||
lcl/include/dbradiogroup.inc svneol=native#text/pascal
|
lcl/include/dbradiogroup.inc svneol=native#text/pascal
|
||||||
|
@ -344,6 +344,68 @@ Type
|
|||||||
property ValueUnchecked: string read FValueUncheck write SetValueUncheck;
|
property ValueUnchecked: string read FValueUncheck write SetValueUncheck;
|
||||||
property Visible;
|
property Visible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TDBComboBox }
|
||||||
|
|
||||||
|
TDBComboBox = class(TCustomComboBox)
|
||||||
|
private
|
||||||
|
FDataLink: TFieldDataLink;
|
||||||
|
function GetDataField: string;
|
||||||
|
function GetDataSource: TDataSource;
|
||||||
|
function GetField: TField;
|
||||||
|
function GetReadOnly: Boolean;
|
||||||
|
procedure SetDataField(const AValue: string);
|
||||||
|
procedure SetDataSource(const AValue: TDataSource);
|
||||||
|
procedure SetReadOnly(const AValue: Boolean);
|
||||||
|
protected
|
||||||
|
function GetComboText: string; virtual;
|
||||||
|
procedure SetComboText(const NewText: string); virtual;
|
||||||
|
procedure DataChange(Sender: TObject); virtual;
|
||||||
|
procedure EditingChange(Sender: TObject); virtual;
|
||||||
|
procedure UpdateData(Sender: TObject); virtual;
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
property Field: TField read GetField;
|
||||||
|
property Text;
|
||||||
|
property ItemIndex;
|
||||||
|
published
|
||||||
|
property Anchors;
|
||||||
|
property ArrowKeysTraverseList;
|
||||||
|
property AutoDropDown;
|
||||||
|
property Ctl3D;
|
||||||
|
property DataField: string read GetDataField write SetDataField;
|
||||||
|
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||||
|
property DropDownCount;
|
||||||
|
property Enabled;
|
||||||
|
property Font;
|
||||||
|
property ItemHeight;
|
||||||
|
property Items write SetItems;
|
||||||
|
property ItemWidth;
|
||||||
|
property MaxLength default -1;
|
||||||
|
property OnChange;
|
||||||
|
property OnClick;
|
||||||
|
property OnCloseUp;
|
||||||
|
property OnDrawItem;
|
||||||
|
property OnDropDown;
|
||||||
|
property OnEnter;
|
||||||
|
property OnExit;
|
||||||
|
Property OnKeyDown;
|
||||||
|
property OnKeyPress;
|
||||||
|
Property OnKeyUp;
|
||||||
|
property ParentCtl3D;
|
||||||
|
property ParentFont;
|
||||||
|
property ParentShowHint;
|
||||||
|
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||||||
|
property ShowHint;
|
||||||
|
property Sorted;
|
||||||
|
property Style;
|
||||||
|
property TabOrder;
|
||||||
|
property TabStop;
|
||||||
|
property Visible;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
// ToDo: Move this to db.pp
|
// ToDo: Move this to db.pp
|
||||||
function ExtractFieldName(const Fields: string; var StartPos: Integer): string;
|
function ExtractFieldName(const Fields: string; var StartPos: Integer): string;
|
||||||
@ -675,12 +737,16 @@ end;
|
|||||||
{$Include dblistbox.inc}
|
{$Include dblistbox.inc}
|
||||||
{$Include dbradiogroup.inc}
|
{$Include dbradiogroup.inc}
|
||||||
{$Include dbcheckbox.inc}
|
{$Include dbcheckbox.inc}
|
||||||
|
{$Include dbcombobox.inc}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.5 2003/09/18 10:50:05 mattias
|
||||||
|
started TDBComboBox
|
||||||
|
|
||||||
Revision 1.4 2003/09/16 11:35:14 mattias
|
Revision 1.4 2003/09/16 11:35:14 mattias
|
||||||
started TDBCheckBox
|
started TDBCheckBox
|
||||||
|
|
||||||
|
129
lcl/include/dbcombobox.inc
Normal file
129
lcl/include/dbcombobox.inc
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
// included by dbctrls.pas
|
||||||
|
{
|
||||||
|
*****************************************************************************
|
||||||
|
* *
|
||||||
|
* This file is part of the Lazarus Component Library (LCL) *
|
||||||
|
* *
|
||||||
|
* See the file COPYING.LCL, included in this distribution, *
|
||||||
|
* for details about the copyright. *
|
||||||
|
* *
|
||||||
|
* This program 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. *
|
||||||
|
* *
|
||||||
|
*****************************************************************************
|
||||||
|
}
|
||||||
|
|
||||||
|
{ TDBComboBox }
|
||||||
|
|
||||||
|
function TDBComboBox.GetDataField: string;
|
||||||
|
begin
|
||||||
|
Result := FDataLink.FieldName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBComboBox.GetDataSource: TDataSource;
|
||||||
|
begin
|
||||||
|
Result := FDataLink.DataSource;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBComboBox.GetField: TField;
|
||||||
|
begin
|
||||||
|
Result := FDataLink.Field;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBComboBox.GetReadOnly: Boolean;
|
||||||
|
begin
|
||||||
|
Result := FDataLink.ReadOnly;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.SetDataField(const AValue: string);
|
||||||
|
begin
|
||||||
|
FDataLink.FieldName := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.SetDataSource(const AValue: TDataSource);
|
||||||
|
begin
|
||||||
|
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
|
||||||
|
FDataLink.DataSource := AValue;
|
||||||
|
if AValue <> nil then
|
||||||
|
AValue.FreeNotification(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.SetReadOnly(const AValue: Boolean);
|
||||||
|
begin
|
||||||
|
FDataLink.ReadOnly := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBComboBox.GetComboText: string;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if Style in [csDropDown,csSimple] then
|
||||||
|
Result:=Text
|
||||||
|
else begin
|
||||||
|
i:=ItemIndex;
|
||||||
|
if i<0 then
|
||||||
|
Result := ''
|
||||||
|
else
|
||||||
|
Result := Items[i];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.SetComboText(const NewText: string);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if NewText=GetComboText then exit;
|
||||||
|
if NewText='' then
|
||||||
|
i:=-1
|
||||||
|
else
|
||||||
|
i:=Items.IndexOf(NewText);
|
||||||
|
ItemIndex:=i;
|
||||||
|
if ItemIndex>=0 then Exit;
|
||||||
|
if Style in [csDropDown,csSimple] then Text:=NewText;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.DataChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if not (Style = csSimple) and DroppedDown then Exit;
|
||||||
|
if FDataLink.Field <> nil then
|
||||||
|
// ToDo: use Field.Text
|
||||||
|
SetComboText(FDataLink.Field.DisplayText)
|
||||||
|
else
|
||||||
|
if csDesigning in ComponentState then
|
||||||
|
SetComboText(Name)
|
||||||
|
else
|
||||||
|
SetComboText('');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.EditingChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// ToDo
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDBComboBox.UpdateData(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// ToDo: use Field.Text
|
||||||
|
FDataLink.Field.AsString:=GetComboText;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TDBComboBox.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
ControlStyle := ControlStyle+[csReplicatable];
|
||||||
|
FDataLink := TFieldDataLink.Create;
|
||||||
|
FDataLink.Control := Self;
|
||||||
|
FDataLink.OnDataChange := @DataChange;
|
||||||
|
FDataLink.OnUpdateData := @UpdateData;
|
||||||
|
FDataLink.OnEditingChange := @EditingChange;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TDBComboBox.Destroy;
|
||||||
|
begin
|
||||||
|
FDataLink.Free;
|
||||||
|
FDataLink := nil;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// included by dbctrls.pas
|
||||||
|
|
@ -120,7 +120,9 @@ end;
|
|||||||
|
|
||||||
function TDBRadioGroup.GetButtonValue(Index: Integer): string;
|
function TDBRadioGroup.GetButtonValue(Index: Integer): string;
|
||||||
begin
|
begin
|
||||||
if (Index<FValues.Count) and (FValues[Index]<>'') then
|
if Index<0 then
|
||||||
|
Result:=''
|
||||||
|
else if (Index<FValues.Count) and (FValues[Index]<>'') then
|
||||||
Result:=FValues[Index]
|
Result:=FValues[Index]
|
||||||
else if Index<Items.Count then
|
else if Index<Items.Count then
|
||||||
Result:=Items[Index]
|
Result:=Items[Index]
|
||||||
|
Loading…
Reference in New Issue
Block a user