|
Home
Components
Wizards
Tips & Trics
Samples
Programs
Links
What's new
About Kukvar
EMail
Sign
Guestbook
View
Guestbook
|
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.
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
uses ToolIntf,Exptintf;
procedure fgfgfgfg; var
s: string; begin
if ToolServices = nil then Exit; S:=ToolServices.GetProjectName; ShowMessage(s); end;
Back To Top
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
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
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
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
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
uses
TypeInfo;
function IsDataAwareComponent(AClass: TClass): Boolean; begin
Result:= (GetPropInfo(AClass.ClassInfo,'DataSource') <> nil); end;
Back To Top
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
|