Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Get count of members in record (https://www.delphipraxis.net/145892-get-count-members-record.html)

nanix 10. Jan 2010 11:07


Get count of members in record
 
Delphi-Quellcode:
PerfFormattedData_PerfOS_Processor = record
  C1TransitionsPerSec: String;
  C2TransitionsPerSec: String;
  C3TransitionsPerSec: String;
  Caption: String;
  Description: String;
  DPCRate: String;
  DPCsQueuedPerSec: String;
  Frequency_Object: String;
  Frequency_PerfTime: String;
  Frequency_Sys100NS: String;
  InterruptsPerSec: String;
  Name: String;
  PercentC1Time: String;
  PercentC2Time: String;
  PercentC3Time: String;
  PercentDPCTime: String;
  PercentIdleTime: String;
  PercentInterruptTime: String;
  PercentPrivilegedTime: String;
  PercentProcessorTime: String;
  PercentUserTime: String;
  Timestamp_Object: String;
  Timestamp_PerfTime: String;
  Timestamp_Sys100NS: String;
end;

var
WMI_PerfFormattedData_PerfOS_Processor:array of PerfFormattedData_PerfOS_Processor;
so i could do something like this so i could reduce the code size
Delphi-Quellcode:
 WMI_PerfFormattedData_PerfOS_Processor[i].Property[i2]

mkinzler 10. Jan 2010 11:18

Re: Get count of members in record
 
No, because the Entries are named not indexed.

nanix 10. Jan 2010 11:20

Re: Get count of members in record
 
Well how could this be done then?Couse i have like 30 records :gruebel:

changing everything would be nightmare



Maybe

Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor[i].Property(WMI.GetPropertyName[i2]):=WMIResults

himitsu 10. Jan 2010 11:33

Re: Get count of members in record
 
If you want to have such functionality, then you must implement it yourself.

Since Delphi 2010 it is could possibly even take the new RTTI support.




since Delphi 2006 / Turbo Delphi

Delphi-Quellcode:
TPerfFormattedData_PerfOS_Processor = record
  C1TransitionsPerSec: String;
  C2TransitionsPerSec: String;
  ...
  Timestamp_Sys100NS: String;
private
  function GetProp(i: Integer): String;
public
  property Prop[i: Integer]: String read GetProp;
end;
or

Delphi-Quellcode:
TPerfFormattedData_PerfOS_Processor = record
  C1TransitionsPerSec: String;
  C2TransitionsPerSec: String;
  ...
  Timestamp_Sys100NS: String;
end;

TPerfFormattedData_PerfOS_Processor_Helper = record helper for TPerfFormattedData_PerfOS_Processor
private
  function GetProp(i: Integer): String;
public
  property Prop[i: Integer]: String read GetProp;
end;
Delphi-Quellcode:
function TPerfFormattedData_PerfOS_Processor{_Helper}.GetProp(i: Integer): String;
begin
  case i of
    0: Result := C1TransitionsPerSec;
    1: Result := C2TransitionsPerSec;
    ...
    23: Result := Timestamp_Sys100NS;
    else Raise Exception.Create('invalid index');
  end;
end;

thkerkmann 10. Jan 2010 11:35

Re: Get count of members in record
 
Hi,

if it's all string data ? why not use a dictionary instead of a record:

Use a tStringlist and add values like "ProcessorName=Intel Core2"

regards

nanix 10. Jan 2010 11:38

Re: Get count of members in record
 
Thanks for the information but such concept isnt possible ? By name not by index

Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor[i].Property(WMI.GetPropertyName[i2]):=WMIResults

himitsu 10. Jan 2010 11:48

Re: Get count of members in record
 
Delphi-Quellcode:
private
  function GetProp(Name: String): String;
public
  property Prop[Name: String]: String read GetProp;
end;

nanix 10. Jan 2010 11:51

Re: Get count of members in record
 
yea himitsu add all these functions for each record i have over 35 would be mad crazy :gruebel: :oops:

himitsu 10. Jan 2010 12:02

Re: Get count of members in record
 
Zitat:

Zitat von nanix
yea himitsu add all these functions for each record i have over 35 would be mad crazy :gruebel: :oops:

Well, whoever wants it easier later, you first have to invest some work.


Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor: array of StringList;
Hier im Forum suchenTDictionary
Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor: array of TDictionary;
http://www.delphipraxis.net/internal...t.php?t=156343
Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor: array of TAssocArray<String>;
declared in Hier im Forum suchenhimXML.pas
Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor: array of TAssocStringArray;
...

nanix 10. Jan 2010 12:24

Re: Get count of members in record
 
Can you explain to me whats the advantage to use

Delphi-Quellcode:
WMI_PerfFormattedData_PerfOS_Processor: array of TAssocArray<String>;


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:05 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz