Experts & Wizards, Tools & Components for Borland Delphi

Home
Components
Wizards
Tips & Trics
Samples
Programs
Links
What's new
About Kukvar
EMail
Sign Guestbook
View Guestbook

Tips & Trics

Below is a list of tips and tricks that I have answered on the various newsgroups relating to Borland Delphi. These tips are tested for Delphi4 and should work.


How to place a component on a TDataModule (or TForm) at design time using a property editor or Component editor?

See units EditIntf, DsgnIntf in Source/ToolsApi. If Parent is nil, and the component to be added is a TWinControl, then it is parented to the currently selected container. If Parent is non-nil, and it is a TWinControl, then the component is parented to that control. The component's name to be auto-generated. Set Left and Top to -1 to use the default size of the component. Set Width and Height to -1 to center the component on the form.


uses StdCtrls;

{TAnyEditor = class( any PropertyEditor or any ComponentEditor)} procedure TAnyEditor.SetValue(const Value: string);
begin inherited;
if not Designer.IsSourceReadOnly then Designer.CreateComponent(TEdit{GetClass(Value)},
nil{Parent},-1,-1,-1,-1);
end;

Back To Top

How to find the curent project file name at design time?


uses ToolIntf,Exptintf;

procedure fgfgfgfg;
var s: string;
begin if ToolServices = nil then Exit;
S:=ToolServices.GetProjectName;
ShowMessage(s);
end;
Back To Top

How can I check in the expert, if any component exists in the form (or in the code)?

Back To Top


Is it possible to get a list of all the components registered in the Component palette?

uses ToolIntf,Exptintf;

procedure TDBWizardForm.FormCreate(Sender: TObject);
var i,k: Integer; begin CBAncestor.Items.Clear; for i:=0 to ToolServices.GetModuleCount-1 do begin for k:=0 to ToolServices.GetComponentCount(i)-1 do CBAncestor.Items.Add(ToolServices.GetComponentName(i,k)); end;
end;
Back To Top

How to get list of all components registered?


uses TypInfo,ToolIntf,Exptintf,LibIntf;
procedure TDBWizardForm.FormCreate(Sender: TObject);
var i,k: Integer; CRef: TClass; StrName: String[255];
begin CBAncestor.Items.Clear; for i:=0 to ToolServices.GetModuleCount-1 do begin for k:=0 to ToolServices.GetComponentCount(i)-1 do begin CRef:= TClass(GetClass(ToolServices.GetComponentName(i,k))); while CRef <> nil do begin StrName:= CRef.ClassName; if CBAncestor.Items.IndexOf(StrName) = -1
then CBAncestor.Items.Add(StrName);
if StrName <> 'TComponent'
then CRef:= CRef.ClassParent
else CRef:= nil;
end;
end;
end;
CBAncestor.Sorted:=
true;
end;

Back To Top

How to get a list of all page names of the Component palette?


uses Registry;

procedure GetPalettePageList(const PalettePageList: TStrings);
var Reg: TRegistry; n: Integer; begin Reg:=TRegistry.Create; try if Reg.OpenKeyReadOnly('Software\Borland\Delphi\4.0\Palette') then Reg.GetValueNames(PalettePageList); finally Reg.Free; end;
for n:=0 to PalettePageList.Count-1 do if pos('.',PalettePageList.Strings[n]) > 0
then PalettePageList.Delete(n);
end;

Back To Top

I would like to write a component editor, but the ancestor component already possesses 3 items in its menu, as I do to include an item in this menu without losing the ones that they already exist ?


uses ...,DsgnIntf;
type TMyComponentEditor = class(TAncestorEditor)
function GetVerbCount: integer; override;
function GetVerb(index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;

implementation { TMyComponentEditor } procedure TMyComponentEditor.ExecuteVerb(Index: Integer);
begin if Index=GetVerbCount-1 then {Execute Your Editor} else inherited GetVerb(Index);
end;

function TMyComponentEditor.GetVerb(index: Integer): string;
begin if Index=GetVerbCount-1 then Result:= 'Your Editor'
else Result:= inherited GetVerb(Index);
end;

function TMyComponentEditor.GetVerbCount: integer;
begin Result:= inherited GetVerbCount+1;
end;

Back To Top

I have a component with a published collection. I need to display the
standard collection editor for one of the component editor verbs. How do I do this?


NB!!!: for Delphi4 You should add package dclsdt40.dcp 
from directory /Lib to Requires folder at Package editor

procedure Register;
implementation uses DsgnIntf, ColnEdit; type TAnyEditor = class(TComponentEditor)
function GetVerb(index : integer) : string ; override ;
function GetVerbCount : integer ; override ;
procedure ExecuteVerb(index : integer) ; override ;
end;

procedure Register;
begin RegisterComponentEditor(TEditedComponent,TAnyEditor) ; end;

{ ShowCollectionEditor(ADesigner: IDesigner; AComponent: TComponent;
ACollection: TCollection; const PropertyName: string); }
procedure TAnyEditor.ExecuteVerb(index: integer);
begin if index = GetVerbCount - 1 then ShowCollectionEditor(Designer,Component, (Component as TEditedComponent).Params, 'Params')
else inherited ExecuteVerb(index) ;
end;

function TAnyEditor.GetVerb(index: integer): string;
begin if index = GetVerbCount -1 then Result := 'Any Editor' else Result := inherited GetVerb(index) ;
end;

function TAnyEditor.GetVerbCount: integer;
begin Result := inherited GetVerbCount + 1 ;
end;

Back To Top

How to determine if a component is data-aware at runtime?


uses
TypeInfo;
function IsDataAwareComponent(AClass: TClass): Boolean;
begin Result:= (GetPropInfo(AClass.ClassInfo,'DataSource') <> nil);
end;

Back To Top

Is it possible somehow to hide all or some of the gridoptions in a component derived from TStringgrid?

Published property it is impossible move to more protected section. Published property will become invisible if you will do his for reading only.

My solution:


interface
{...}
TImpactGridOption = (igColumnResize, igColLines, igRowLines, igTabs,
igMultiSelect);
TImpactGridOptions = set of TImpactGridOption;

TImpactGrid =
class(TCustomGrid)
private { Private declarations } FOptions: TImpactGridOptions; procedure SetOptions(Value: TImpactGridOptions);
published property Options: TImpactGridOptions read FOptions write SetOptions
default [igColumnResize, igColLines,
igRowLines, igTabs ];
end;

implementation {...} procedure TImpactGrid.SetOptions(Value: TImpactGridOptions);
const LayoutOptions = [igColLines, igRowLines]; var NewGridOptions: TGridOptions; ChangedOptions: TImpactGridOptions; begin if FOptions <> Value then begin NewGridOptions := []; if igColLines in Value then NewGridOptions := NewGridOptions + [goFixedVertLine, goVertLine]; if igRowLines in Value then NewGridOptions := NewGridOptions + [goFixedHorzLine, goHorzLine]; if igColumnResize in Value then NewGridOptions := NewGridOptions + [goColSizing, goColMoving]; if igTabs in Value then Include(NewGridOptions, goTabs);

Include(NewGridOptions, goRowSelect);
Exclude(NewGridOptions, goAlwaysShowEditor);
Exclude(NewGridOptions, goEditing);

inherited Options := NewGridOptions;
if igMultiSelect in (FOptions - Value) then {...};
ChangedOptions := (FOptions + Value) - (FOptions * Value);
FOptions := Value;

end;
end;

Back To Top

Back To Top
Home Page
press control + D to bookmark this site.

Copyright © 1999 KUKVAR LTD. All rights reserved.

Last modified: January 1, 1970 GMT