Board index » delphi » Setting Text Property

Setting Text Property

I thought this should be quite simple but....

I want to implement a facility to copy the previous controls contents to the
current control (like Access does) so I implemented the code shown below.
While the cursor is on the control everything appears to work fine but as
soon as you tab off the text disappears. I'd rather use the TCustomEdit
rather the TCustomMaskEdit but it has no text property.  How can I make the
text property stay changed?

Thanks
Simon

procedure TfrmCustomer.wwDBEdit6KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  CtrlList: TList;
  PrevCtrl: TWinControl;
begin
  if (Shift = [ssCtrl]) and (Key = 192) then begin
     CtrlList := TList.Create;
     try
        (Sender as TWinControl).Parent.GetTabOrderList(CtrlList);
        PrevCtrl := CtrlList[CtrlList.IndexOf((Sender as TWinControl)) - 1];
        if (PrevCtrl is TCustomMaskEdit) and (Sender is TCustomMaskEdit)
then
           (Sender as TCustomMaskEdit).
           (Sender as TCustomMaskEdit).Text := (PrevCtrl as
TCustomMaskEdit).Text;
     finally
        CtrlList.Free;
     end;
  end;
end;

 

Re:Setting Text Property


Quote
In article <3bb2104b_2@dnews>, Simon Bowyer wrote:
> I thought this should be quite simple but....
> I want to implement a facility to copy the previous controls contents to the
> current control (like Access does) so I implemented the code shown below.
> While the cursor is on the control everything appears to work fine but as
> soon as you tab off the text disappears. I'd rather use the TCustomEdit
> rather the TCustomMaskEdit but it has no text property.  How can I make the
> text property stay changed?

We are talking about database controls i assume? For those you should never
set the control content in code directly, instead set the field of the dataset
the control is linked to. The control will update itself from the dataset when
it gains focus, and that is the reason why the text you set disappears again.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads