home *** CD-ROM | disk | FTP | other *** search
- QDBPanel v2.00 Beta Release 3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- This is the third beta release of QDBPanel for QDB v2.00. QDB itself is
- now ready for release but QDBPanel remains in beta for a while longer as
- certain design issues still need to be addressed.
-
- There is no help file for this release -- this file will have to serve
- for the moment.
-
- Please be aware that you are quite likely to find bugs or other problems.
- Please let me know about them at rrm@sprynet.com. Thanks for your help.
- If you have any ideas for QDBPanel send them along too. A related
- component, QDBGrid, is still in the alpha stage.
-
- QDBPanel, which remains free, is Copyright (c) 1997 Robert R. Marsh, SJ &
- the British Province of the Society of Jesus.
-
-
- Usage
- ~~~~~
- The QDBPanel simplifies the storage and retrieval of items via QDB. You
- just drop a QDBPanel on a form and place on it whatever components you
- wish to use. The panel knows how to save and load the controls' contents
- in a QDB file. QDBPanel knows how to handle most common controls: those
- which derive from TCustomEdit, TRichEdit, TCustomRadioGroup,
- TCustomCheckBox, TCustomComboBox, TCustomListBox, & TImage. Other controls
- (like TLabel) are ignored. Controls contained by a TPageControl are also
- stored but not those handled by TTabNotebook.
-
- If you want to store other data but don't want it to be visible at run-
- time you can drop an ordinary panel on the QDBPanel and set its Visible
- property to false. Any controls dropped onto this "invisible" panel
- will be stored along with the visible ones.
-
- On the other hand, if you want some controls on the QDBPanel to be
- visible but not stored you can enclose them in an ordinary panel with its
- Tag property set to -999. The controls will still be visible and
- available but they will not be included in the QDB. Individual controls
- can be excluded in the same way by setting their Tag to -999.
-
-
- QDBPanel has the published properties:
-
- Enabled: boolean;
- Enables/disables the panel and all the controls on it.
-
- ExcludeTag: longint;
- The value of the tag used to signify a control should be
- excluded.
-
- FieldCount: integer;
- The number of fields defined by the panel. (read-only)
-
- FieldNames[index: integer]: string;
- The names of the fields (i.e., the control names). (read-only)
-
- QDB: TQDB;
- The QDB file associated with the panel.
-
- QDBPanel requires a handler for the OnKey event:
-
- OnKey: procedure (Sender: TObject; var key: TKey) of object;
- which is called by the Fetch method (see below) to collect a key by
- which to store and retrieve an item.
-
- QDBPanel has the following public methods:
-
- procedure Clear;
- Clears all the controls placed on QDBPanel.
-
- procedure Store;
- Stores the contents of the controls on the panel to the QDB file.
-
- procedure Fetch;
- Loads the current item of the QDB file into the controls on the
- QDBPanel.
-
- procedure Post;
- If Enabled saves the panel item to the QDB and makes Enabled false.
-
- procedure Edit;
- Sets Enabled true to allow editing of the panel item.
-
- procedure Cancel;
- Cancels editing and reloads the panel item.
-
- procedure Insert;
- Clears the panel and allows editing.
-
- procedure Refresh;
- Reloads the panel item.
-
- procedure Delete;
- Deletes the current item, turns off editing and loads the new item
- onto the panel.
-
- procedure FirstItem;
- Loads the first item of the QDB file onto the panel.
-
- procedure PrevItem;
- Loads the previous item of the QDB file onto the panel.
-
- procedure NextItem;
- Loads the next item of the QDB file onto the panel.
-
- procedure LastItem;
- Loads the last item of the QDB file onto the panel.
-
- function FileIsValid: boolean;
- (has been removed for the moment will probably return!)
-
- Extending QDBPanel
- ~~~~~~~~~~~~~~~~~~
- If the controls you wish to use with QDBPanel descend from the default
- controls listed above, there is nothing more you need to do. Just drop
- them on the panel and that's it. You can, however, override and extend
- the default behaviors if necessary.
-
- procedure RegisterProcs(AClass: TControlClass; ClearProc, FetchProc,
- StoreProc: TClassProc);
-
- If you wish to override the default storage behavior of already
- registered controls or to provide instructions for handling other kinds of
- controls you use the RegisterProcs method to pass along three procedures
- of type TClassProc:
-
- type TClassProc = procedure(AControl: TControl; Stream: TStream);
-
- The ClearProc clears the control, FetchProc loads its contents from
- Stream, and StoreProc saves to Stream. The most recently registered
- procedures take precedence, permitting default behaviour to be overridden.
- For example, an edit box saves its contents as text but you may have a
- descendant of TCustomEdit, TIntegerBox that handles integers. By
- registering new procedures for TIntegerBox it can be made to store its
- data in a new format while retaingin the default bahavior for all other
- edit boxes.
-
- By default, Edit components store their text. The radio group and check
- box store their state. Combo boxes store the chosen text while list boxes
- record which list items are selected. Images ...
-
- The following examples illustrate how TCustomRadioGroup and TCustomEdit
- are handled.
-
- RegisterProcs(TCustomEdit,ClearCustomEdit,FetchCustomEdit,StoreCustomEdit);
-
- procedure ClearCustomEdit(AControl: TControl; Stream: TStream);
- begin
- (AControl as TCustomEdit).Text := '';
- end;
-
- procedure FetchCustomEdit(AControl: TControl; Stream: TStream);
- var
- con: TCustomEdit;
- p: pchar;
- begin
- con := (AControl as TCustomEdit);
- p := StrAlloc(Stream.Size);
- try
- Stream.ReadBuffer(p^, Stream.Size);
- con.SetTextBuf(p);
- finally
- StrDispose(p);
- 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;
-
- RegisterProcs(TCustomRadioGroup,ClearCustomRadioGroup,FetchCustomRadioGroup,StoreCustomRadioGroup);
-
- procedure ClearCustomRadioGroup(AControl: TControl; Stream: TStream);
- begin
- TRadioGroup(AControl).ItemIndex := -1;
- end;
-
- procedure FetchCustomRadioGroup(AControl: TControl; Stream: TStream);
- var
- n: longint;
- begin
- Stream.ReadBuffer(n, SizeOf(n));
- TRadioGroup(AControl).ItemIndex := n;
- end;
-
- procedure StoreCustomRadioGroup(AControl: TControl; Stream: TStream);
- var
- n: longint;
- begin
- n := TRadioGroup(AControl).ItemIndex;
- Stream.WriteBuffer(n, SizeOf(n));
- end;
-
- Finally a note about the default handling of TImage descendants.
- QDBPanel knows how to load and save bitmaps, metafiles, and icons
- but you may, for example, have added support for jpeg files. You must
- tell QDBPanel of added graphic formats using the RegisterGraphicFormat
- method:
-
- procedure RegisterGraphicFormat(AExtension: string; AGraphicClass: TGraphicClass);
-
- For example, to register the new Delphi 3 jpg format you would write:
-
- RegisterGraphicFormat('jpg',TJPEGImage);
-
-
- TQDBPanel is still being developed. I hope it looks useful. The new demos
- (add_book.zip and animals.zip) show how easy it is to use,
-
- Robert R. Marsh, SJ
- 17th November 1997
-