Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Delphi 2 component
Mon, Dec 17 2007 10:03 AMPermanent Link

"Rita"
If the kids aunts and so on get you down over xmas
can you make these D2 data aware buttons work
for Dbisam 4 and D7 WinkI would love a data button
that displays the field content and there is such a beast
in this zip.
Thanks Rita





Attachments: buttons.zip
Mon, Dec 17 2007 2:09 PMPermanent Link

Sean McCall
Rita,

It's not real difficult to roll your own. If you have the code for the
VCL look at how a TFieldDataLink works in the DBCtrls unit. The
following is untested, but will probably do the trick.

Sean

TDBButton = class(TButton)
private
  FDataLink: TFieldDataLink;
protected
  function GetDataField: String;
  function GetDataSource: TDataSource;
  procedure SetDataField(const AValue: String);
  procedure SetDataSource(Value: TDataSource);
published
  property DataField: string read GetDataField write SetDataField;
  property DataSource: TDataSource read GetDataSource write          
        SetDataSource;
end;

constructor TDBButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;
  (*
  These are probably not needed for a button...

  FDataLink.OnEditingChange := EditingChange;
  FDataLink.OnUpdateData := UpdateData;
  FDataLink.OnActiveChange := ActiveChange;
  *)
end; {constructor}

destructor TDBButton.Destroy;
begin
  inherited;
  FreeAndNil(FDataLink);
end;

procedure TDBButton.DataChange(Sender: TObject);
begin
  if FDataLink.Field <> nil then begin
    Caption := FDataLink.Field.Text;
  end; {if linked to a field}
end;

function TDBButton.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TDBButton.SetDataSource(AValue: TDataSource);
begin
  if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
    FDataLink.DataSource := AValue;
  if Value <> nil then Value.FreeNotification(Self);
end;

function TDBButton.GetDataField: string;
begin
  Result := FDataLink.FieldName;
end;

procedure TDBButton.SetDataField(const AValue: string);
begin
  FDataLink.FieldName := AValue;
end;

Tue, Dec 18 2007 4:41 AMPermanent Link

"Rita"
Cool thanks Sean u could have done the
whole thing being the season of goodwill
an all Wink

Rita CheekyBum


"Sean McCall" <someone@somewhere.net> wrote in message
news:5CE2E654-A18B-4E58-9A86-C06F34262154@news.elevatesoft.com...
> Rita,
>
> It's not real difficult to roll your own. If you have the code for the VCL
> look at how a TFieldDataLink works in the DBCtrls unit. The following is
> untested, but will probably do the trick.
>
> Sean
>
> TDBButton = class(TButton)
> private
>   FDataLink: TFieldDataLink;
> protected
>   function GetDataField: String;
>   function GetDataSource: TDataSource;
>   procedure SetDataField(const AValue: String);
>   procedure SetDataSource(Value: TDataSource);
> published
>   property DataField: string read GetDataField write SetDataField;
>   property DataSource: TDataSource read GetDataSource write SetDataSource;
> end;
>
> constructor TDBButton.Create(AOwner: TComponent);
> begin
>   inherited Create(AOwner);
>   FDataLink := TFieldDataLink.Create;
>   FDataLink.Control := Self;
>   FDataLink.OnDataChange := DataChange;
>   (*
>   These are probably not needed for a button...
>
>   FDataLink.OnEditingChange := EditingChange;
>   FDataLink.OnUpdateData := UpdateData;
>   FDataLink.OnActiveChange := ActiveChange;
>   *)
> end; {constructor}
>
> destructor TDBButton.Destroy;
> begin
>   inherited;
>   FreeAndNil(FDataLink);
> end;
>
> procedure TDBButton.DataChange(Sender: TObject);
> begin
>   if FDataLink.Field <> nil then begin
>     Caption := FDataLink.Field.Text;
>   end; {if linked to a field}
> end;
>
> function TDBButton.GetDataSource: TDataSource;
> begin
>   Result := FDataLink.DataSource;
> end;
>
> procedure TDBButton.SetDataSource(AValue: TDataSource);
> begin
>   if not (FDataLink.DataSourceFixed and (csLoading in ComponentState))
> then
>     FDataLink.DataSource := AValue;
>   if Value <> nil then Value.FreeNotification(Self);
> end;
>
> function TDBButton.GetDataField: string;
> begin
>   Result := FDataLink.FieldName;
> end;
>
> procedure TDBButton.SetDataField(const AValue: string);
> begin
>   FDataLink.FieldName := AValue;
> end;
>
>

Image