Applies To
TQDBView
Declaration
procedure RegisterControl(AClass : TControlClass; FieldType : TFieldType; ClearProc, FetchProc, StoreProc : TClassProc);
Description
RegisterControl is used to tell TQDBView how to deal with a particular class of control (or its descendants). The TQDBView constructor uses RegisterControl to provide the default behavior for Edit boxes, listboxes, images, etc. You only need to bother with RegisterControl if you wish to override the default behavior or add a new type of control.
QDBView needs to be provided with procedures (of type TClassProc) to clear a control, to fetch its contents, and to store its contents.
For example, to register descendants of TCustomEdit use:
RegisterControl(TCustomEdit, ftstring, ClearCustomEdit, FetchCustomEdit, StoreCustomEdit);
with:
// here Stream is irrelevant
procedure ClearCustomEdit(AControl : TControl; Stream : TStream);
begin
// simply blank the control
(AControl as TCustomEdit).Text := '';
end;
// Stream contains the data for this field only in whatever format you have chosen
// Here data is stored as a simple string
procedure FetchCustomEdit(AControl : TControl; Stream : TStream);
var
con : TCustomEdit;
p : pchar;
Len : longint;
begin
try
Len := Stream.size;
if Len = 0 then
Abort;
con := (AControl as TCustomEdit);
p := StrAlloc(Len);
try
Stream.ReadBuffer(p^, Len);
con.SetTextBuf(p);
finally
StrDispose(p);
end;
except
// if Fetch fails it should always Clear the control
ClearCustomEdit(AControl, Stream);
end;
end;
procedure StoreCustomEdit(AControl : TControl; Stream : TStream);
var
con : TCustomEdit;
Len : longint;
p : pchar;
begin
con := (AControl as TCustomEdit);
Len := con.GetTextLen + 1;
p := StrAlloc(Len);
try
con.GetTextBuf(p, Len);
Stream.Write(p^, Len);
finally
StrDispose(p);
end;
end;