Solved

Component writing question

Posted on 1998-10-23
8
140 Views
Last Modified: 2010-04-06
I am trying to write a component which will enumerate all the drives in a system and report back various parameters for each drive.  I want the information to be returned as a list, but each item returned must contain various info such as serial number, volume label, drive type, size etc.

How do I create a property like that?

For instance, I want the Object Inspector to show something like this for the drives property:

   - Drives
        DriveA   \/
        DriveC   \/
        DriveD   \/
        DriveG   \/
        DriveZ   \/
             VolLabel  NetServer
             SerialNo  F1203AC1
             DiskSize  1,200,304Kb
             DiskFree  912,313Kb
             (etc)

(The \/ means the drop down arrow in a property)

Can someone give me an idea on how to do this??

Thanks in advance.

Stuart
0
Comment
Question by:Stuart_Johnson
8 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1344081
I don't think it is possible to have a varying number of properties for a component when viewed by the object inspector at design time - so to do exactly what you describe is not IMO feasible.

Why do you want to do this? And is your question regarding enumerating the drives, creating the component or showing varying properties in the inspector.

Cheers,

Raymond.
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1344082
Can't help you with the Property Editor stuff, but storing the list is relative easy.
Declare a object that holds all the drive info (vollabel, diskfree..) and then for every drive, create an instance of the object and when you are adding the drive to the list, use AddObject instead of Add. Now, when you click on a drive, a pointer to your object is stored in Items.Objects[no] and you can then typecast it to your object and retreive the information you want..
If you want an example, just say so...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1344083
Stuart,

type
  TDriveProp = class(TObject)
  private
    FDrive    : char;
    FVolLabel : string;
    FSerialNo : integer;
    ...
  private
    procedure SetStringDummy(value: string);
    procedure SetIntDummy(value: integer);
    ...
  public
    constructor Create(drive: char); virtual;
  published
    property VolLabel : string  read FVolLabel write SetStringDummy;
    property SerialNo : integer read FSerialNo write SetIntDummy;
    ...
  end;

constructor TDriveProp.Create(drive: char); virtual;
begin
  inherited;
  FDrive:=drive;
  // Fill FVolLabel, FSerialNo, ...
end;

type
  TDrives = class(TComponent)
  private
    FDriveProps : array ['A'..'Z'] of TDriveProp;
    function  GetDriveProp(index: integer) : TDriveProp;
    procedure SetDriveProp(index: integer; value: TDriveProp);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property DriveA : TDriveProp index 0 read GetDriveProp write SetDrivePop;
    property DriveB : TDriveProp index 1 read GetDriveProp write SetDrivePop;
    property DriveC : TDriveProp index 2 read GetDriveProp write SetDrivePop;
    property DriveD : TDriveProp index 3 read GetDriveProp write SetDrivePop;
    property DriveE : TDriveProp index 4 read GetDriveProp write SetDrivePop;
    ...
  end;

constructor TDrives.Create(AOwner: TComponent);
var ch : char;
begin
  inherited;
  for ch:='A' to 'Z' do
    FDriveProps[ch]:=TDriveProp.Create(ch);
end;

destructor TDrives.Destroy;
begin
  for ch:='A' to 'Z' do
    FDriveProps[ch].Free;
  inherited;
end;

procedure TDrives.SetDriveProp(index: integer; value: TDriveProp); begin end;

function TDrives.GetDriveProp(index: integer) : TDriveProp;
begin
  result:=FDriveProps[char(index+ord('A'))];
end;

Note, that (AFAIK) you'll have to show all 'A'..'Z' drives in the object inspector.
Don't delete the dummy write procedures. Otherwise the properties will not be visible in the object inspector.
Furthermore I'm not sure, if you can put this drives component  into the property of another component (that's what you wanted, isn't it?). I think it is NOT possible. I think you can only have ONE "V".

Regards, Madshi.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1344084
I like Madshi's idea, but I also like the idea of the list.  With the list, is it possible to view them in a dropdown list?  So, if I had five drives (A, C, D, E and Z) they would all be listed in the dropdown list???

I'll have a play with Madshi's idea now and see what I come up with.

Stu.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Accepted Solution

by:
Thaddy earned 160 total points
ID: 1344085
Why not use a collection ?

something like:
type
  TDrivecollection=Class;

  TDrivecollectionItem = class(TcollectionItem)
  private
    Fcapacity: int64;
    Fused: Int64;
    Fdrive: String;
    Ftype: String;
  protected
    { Protected declarations }
  public
    { Public declarations }
     Constructor create(Collection:TCollection);Override;
  published
     property Drive: String read Fdrive write Fdrive;
     property DriveType:String read Ftype write Ftype;
     property BytesUsed:Int64 read Fused write Fused;
     property Capacity:int64 read Fcapacity write Fcapacity;
    { Published declarations }
  end;

  TDriveCollectionItemClass=class Of TcollectionItem;

  TDrivecollection=class(Tcollection)
    private

    protected

    public
      constructor Create(ItemClass:TdriveCollectionItemClass); override;
      destructor Destroy; override;
    published

    end;

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1344086
Thaddy.  How would I incorperate that in the component.  Sorry for the naivity, but this sort of thing is over my head a bit :)

Stu.
0
 
LVL 2

Expert Comment

by:Thaddy
ID: 1344087
You simply derive from Tcomponent and add the TdriveCollection as a property
Delphi itself registers this as a Collection (Like Tmenu or Tactionlist) and voila you even have a propertyeditor.

Look at How Tactionlist is implemented in the VCL, then you get the Idea. What you need is even simpler.

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1344088
Thaddy,

As yet, I havent implemented your idea, and I dont know when and if I will.  I have given you the points regardless.

Thanks all for the help.

Stu.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

25 Experts available now in Live!

Get 1:1 Help Now