Solved

Create component

Posted on 2002-04-22
6
225 Views
Last Modified: 2010-04-04
// --- 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
Comment
Question by:ghjlk
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6959468
? could you explain the sense
(thats above is definitivly wrong)
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6959516
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
 
LVL 1

Accepted Solution

by:
Alone earned 300 total points
ID: 6959844
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:lottol
ID: 6959861
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
 

Author Comment

by:ghjlk
ID: 6960091
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
 
LVL 1

Expert Comment

by:Alone
ID: 6960688
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now