>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
>> Behalf Of Nello Sestini
>> Sent: Thursday, 19 October 2000 00:11
>> To: Multiple recipients of list delphi
>> Subject: Re: [DUG]: Redrawing Components
>> 
>> 
>> Patrick,
>> 
>> > I have a component derived from a Groupbox that displays a button
>> >   [...]
>> > How do I detect when my component has changed in width given that it
>> > inherits a Width property definition from TControl that can't be
>> > overridden
>> > ?
>> 
>> write a handler for the WMSize message.   (example below)

Only works up to a point.

Briefly, the component consists of a TGroupBox containing a TPanel. On the
TPanel is a TDBEdit and a TBitBtn.

The WM_SIZE message handler looks like this:

procedure TGDBEdit.WmSize(var Message : TMessage);
begin
   inherited;
   DBEdit.Width := Self.Width - 35;
   Self.Caption := IntToStr(DBEdit.Width); //added for debugging
   ClearButton.Left := Self.Width - 29;
end;

At design time in the IDE, everything works fine.  When the component is resized
by the user, the button moves itself to remain at the right hand side, and the
DBEdit resizes itself.

But at runtime, the DBEdit remains at its created or default size and does not
resize to fill the control, either when the app first starts up, or when the
component is resized. The caption which should show the new width of the DBEdit
does not change, but always displays the correct value at startup. The button
however will move correctly to the right hand side, always, when the component
is resized.

Here is the source of the component to date:

unit GDBEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, DBCtrls, Buttons, DB;

type
  TGDBEdit = class(TGroupBox)
  private
    { Private declarations }
    function GetDataSource : TDataSource;
    procedure SetDataSource(Value : TDataSource);
    function GetDataField : string;
    procedure SetDataField(Value : string);
    function GetPanelColor : TColor;
    procedure SetPanelColor(Value : TColor);
    procedure WmSize(var Message : TMessage); message WM_SIZE;
  protected
    procedure ClearField(Sender : TObject);
    { Protected declarations }
  public
    { Public declarations }
    DBEdit : TDBEdit;
    ClearButton : TBitBtn;
    Panel : TPanel;
    constructor Create(AOwner : TComponent); override;
  published
    { Published declarations }
    property PanelColor : TColor read GetPanelColor write SetPanelColor;
    property DataSource : TDataSource read GetDataSource write SetDataSource;
    property DataField : string read GetDataField write SetDataField;
  end;

procedure Register;

implementation

procedure TGDBEdit.SetDataSource(Value : TDataSource);
begin
        DBEdit.DataSource := Value;
   if (Value = nil) then begin
      ClearButton.Enabled := false;
   end
   else begin
      ClearButton.Enabled := true;
   end;
end;

function TGDBEdit.GetDataSource : TDataSource;
begin
        Result := DBEdit.DataSource;
end;

procedure TGDBEdit.SetDataField(Value : string);
begin
        DBEdit.DataField := Value;
   if (Value = '') then begin
      ClearButton.Enabled := false;
   end
   else begin
      ClearButton.Enabled := true;
   end;
end;

function TGDBEdit.GetDataField : string;
begin
        Result := DBEdit.DataField;
end;

procedure TGDBEdit.SetPanelColor(Value : TColor);
begin
        Panel.Color := Value;
end;

function TGDBEdit.GetPanelColor : TColor;
begin
        Result := Panel.Color;
end;

procedure TGDBEdit.WmSize(var Message : TMessage);
begin
   DBEdit.Left := Self.Width - 35;
   Self.Caption := IntToStr(DBEdit.Left);
        ClearButton.Left := Self.Width - 29;
   //inherited;
end;

procedure TGDBEdit.ClearField(Sender : TObject);
begin
{   if (DataSource <> nil) then begin
      if (DataField <> '') then begin}
         ShowMessage('Here I am');
         DBEdit.DataSource.DataSet.FieldByName(DBEdit.DataField).Clear;
//      end;
 //  end;
end;

constructor TGDBEdit.Create(AOwner : TComponent);
begin
        inherited Create(AOwner);
   Width := Self.Width - 35;
   Height := 45;
   Color := clYellow;
   Panel := TPanel.Create(Self);
   Panel.Parent := Self;
   Panel.Align := alClient;
   Panel.BevelInner := bvNone;
   Panel.BevelOuter := bvNone;
   Panel.Caption := '';
   Panel.Color := $00C0DCC0;
   DBEdit := TDBEdit.Create(Self);
   DBEdit.Parent := Panel;
   DBEdit.Left := 4;
   DBEdit.Top := 4;
   DBEdit.Width := 65;
   ClearButton := TBitBtn.Create(Self);
   ClearButton.Parent := Panel;
   ClearButton.Kind := bkCancel;
   ClearButton.Caption := '';
   ClearButton.Width := 21;
   ClearButton.Height := 21;
   ClearButton.Top := 4;
   ClearButton.Left := Self.Width - 29;
   if (ComponentState <> [csDesigning]) then begin
      ClearButton.OnClick := ClearField;
   end;
   //ClearButton.Enabled := false;
end;

procedure Register;
begin
  RegisterComponents('Freeware', [TGDBEdit]);
end;

end.

The other problem I am finding is that ClearField is not called when the
bitbutton is pressed, even though it is assigned.



--
Patrick Dunford
BBComp Student 94072485
Home e-mail: [EMAIL PROTECTED]
Mobile: 025 601 7163
**************************************
* Keep Your Association Voluntary!   *
* http://www.geocities.com/cpit_vsm/ *
**************************************

--

----- End forwarded message -----
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to