Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Create component

// --- Create component ---
// I don't know how to create component with this informations
// I want that my new component can add, insert, delete, and other
// functions that are in TComponentList, but with A1, A2, A3, A4, A5, A6

// Thanks.

unit PropertyComponentList;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Menus, StdCtrls, Dialogs, Contnrs;
                                   
type
  PPropertyList = ^AComponentList;
  AComponentList = record
    A1 : Boolean;
    A2 : TStrings;
    A3 : String;
    A4 : TStrings;
    A5 : TStrings;
    A6 : TStrings;
  end;

implementation

procedure Register;
begin
                                   
RegisterComponents('Samples', [PPropertyList]);

end;

end.
0
ghjlk
Asked:
ghjlk
1 Solution
 
kretzschmarCommented:
? could you explain the sense
(thats above is definitivly wrong)
0
 
God_AresCommented:
Well I don't quite know what you ment

but i can tell you you should alway's create a component by using a class. If you want a non visual component i would recomend to derive you component form tcomponent, in code:

Type
  TMyComponent = class(Tcomponent)
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;


If you'll be so kind and tell us some more what you want.
0
 
AloneCommented:
type
  TMyComponent = class(TComponent)
  private
    FA1 : Boolean;
    FA2 : TStrings;
    FA3 : string;
    FA4 : TStrings;
    FA5 : TStrings;
    FA6 : TStrings;
    procedure SetA2(Value: TStrings);
    procedure SetA4(Value: TStrings);
    procedure SetA5(Value: TStrings);
    procedure SetA6(Value: TStrings);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property A1: Boolean read FA1 write FA1 default False;
    property A2: TStrings read FA2 write SetA2;
    property A3: string read FA3 write FA3;
    property A4: TStrings read FA4 write SetA4;
    property A5: TStrings read FA5 write SetA5;
    property A6: TStrings read FA6 write SetA6;
  end;

{ TMyComponent }

constructor TMyComponent.Create(AOwner: TComponent);
begin
  inherited; // default constructor fill all the instance with 0
  FA2 := TStringList.Create;
  FA4 := TStringList.Create;
  FA5 := TStringList.Create;
  FA6 := TStringList.Create;
end;

destructor TMyComponent.Destroy;
begin
  FA6.Free;  // LIFO method recommended for destructors to aviod
  FA5.Free;  // stupid errors
  FA4.Free;
  FA2.Free;
  inherited;
end;

procedure TMyComponent.SetA2(Value: TStrings);
begin
// using of TPersistent.Assign needed for all non-component properties
// to aviod memory leaks and access violations
  if FA2 <> Value then FA2.Assign(Value);
end;

procedure TMyComponent.SetA4(Value: TStrings);
begin
  if FA4 <> Value then FA4.Assign(Value);
end;

procedure TMyComponent.SetA5(Value: TStrings);
begin
  if FA5 <> Value then FA5.Assign(Value);
end;

procedure TMyComponent.SetA6(Value: TStrings);
begin
  if FA6 <> Value then FA6.Assign(Value);
end;

Did I right understood you? ;-)

WBR...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
lottolCommented:
It's problematically to cover all spects of component creating in this thread.
You'd better to read some tutorial about components writing.
if you have Delphi 5, there is DeveloperGuide.pdf file, which is installed with Delphi.
Also this subject is covered in Delphi Help node "Creating Custom Components"
Also it can be downloaded here ftp://ftp.borland.com/pub/delphi/techpubs/delphi5/d5cw.zip

You can find sources for different versions, but general concepts'd be the same.
0
 
ghjlkAuthor Commented:
I tried to create component for putting property in it's variebles like in stringgrid. I need 6 dimensinal list (component). In wich I'll put properties of program parts.

The propeties are :
  A1 : Boolean;
  A2 : TStrings;
  A3 : String;
  A4 : TStrings;
  A5 : TStrings;
  A6 : TStrings;

Thanks.
0
 
AloneCommented:
Do you need a 6-dimensional data array? What's type of your data? Please describe some details of your task.
Otherwise, try to copy/paste my code into unit and then register new TMyComponent. It's fully functional.

WBR...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now