Delphi

How can I get a dataset of in-memory objects?

柔情痞子 提交于 2020-01-01 04:58:12
问题 Does anyone know of a TDataset descendant that works with Generics and RTTI, so that I can write code like this, and make use of data-aware components in the GUI? : ... ds:TDataset<TPerson>; ... procedure DoStuff; begin ds:=TDataset<TPerson>.create; ds.add(TPerson.Create('A.','Hitler',77)); ds.add(TPerson.Create('O.','Bin Laden',88)); end; This should be possible. The fielddefs can be created via RTTI because the exact type of the data is known. Values can also be automatically marshalled

Finding a Windows user's “true” application data folder?

筅森魡賤 提交于 2020-01-01 04:47:11
问题 I have a Delphi 6 application that, like most Windows applications, reads/writes data to the user's "local application data" folder. I use the code below to determine that folder. Up until now, that code worked for most of my users. I have encountered a user whose local application data is not in the expected folder: C:\Users\Bob\AppData\Roaming\ Usually the local app data folder resolves to: C:\Documents and Settings\Bob\Application Data\ What is odd about this user's particular situation is

Is it safe to type-cast TArray<X> to array of X?

江枫思渺然 提交于 2020-01-01 04:08:11
问题 Today I discovered a compiler bug (QC#108577). The following program fails to compile: program Project1; {$APPTYPE CONSOLE} procedure P(M: TArray<TArray<Integer>>); begin SetLength(M, 1, 2); end; begin end. The compiler gags on the SetLength line and says: [dcc32 Error] E2029 ')' expected but ',' found I know I could fix it like this: procedure P(M: TArray<TArray<Integer>>); var i: Integer; begin SetLength(M, 1); for i := low(M) to high(M) do SetLength(M[i], 2); end; but naturally I'm keen to

Is it safe to type-cast TArray<X> to array of X?

≯℡__Kan透↙ 提交于 2020-01-01 04:08:11
问题 Today I discovered a compiler bug (QC#108577). The following program fails to compile: program Project1; {$APPTYPE CONSOLE} procedure P(M: TArray<TArray<Integer>>); begin SetLength(M, 1, 2); end; begin end. The compiler gags on the SetLength line and says: [dcc32 Error] E2029 ')' expected but ',' found I know I could fix it like this: procedure P(M: TArray<TArray<Integer>>); var i: Integer; begin SetLength(M, 1); for i := low(M) to high(M) do SetLength(M[i], 2); end; but naturally I'm keen to

Interface “recursion” and reference counting

喜夏-厌秋 提交于 2020-01-01 03:30:29
问题 I have a small problem with interfaces. Here it is in Pseudo code : type Interface1 = interface end; Interface2 = interface end; TParentClass = class(TInterfacedObject, Interface1) private fChild : Interface2; public procedure AddChild(aChild : Interface2); end; TChildClass = class(TInterfacedObject, Interface2) private fParent : Interface2; public constructor Create(aPArent : Interface1); end; Can anyone see the flaw? I need the child to have a reference to it's parent, but the reference

Issues passing data from DLL to Application

喜夏-厌秋 提交于 2020-01-01 03:30:14
问题 I'm a bit puzzled as to how Pointers should be properly used in my scenario. I have a DLL with some embedded resources in it. I expose a function in this DLL which passes binary data of one of those resources back to its calling app. In this case, I've embedded a JPG image file. My DLL does properly load the file into a resource stream. However from there, the passing it back to the app gets messy. Here's my DLL's code (with a JPG loaded and named SOMERESOURCE ): library ResDLL; {$R *.dres}

'working, please wait' screen with thread?

落爺英雄遲暮 提交于 2020-01-01 03:29:12
问题 Perhaps, it is very easy for you, but I am hard working on a project (for educational purposes) that is querying adsi with TADSISearch component, for several days. I'm trying to show a 'Working, Please wait..' splash screen with a man worker animated gif on Form2 while TADSISearch is searching the Active Directory. Although i tried every possibilities according to me, but i couldn't succeed. I tried to use TADSISearch in a thread, but thread is terminating before ADSIsearch finishes. I think

How to make an application GPO aware?

馋奶兔 提交于 2020-01-01 03:12:30
问题 I'm writing an application in Delphi 2010, and I'd like to provide the option to the administrator to configure it via Group Policy. Any recommendations on good ways to make my application GPO aware? Note, I am only looking to create a computer based GPO, not user. My current solution involves simply first determining if any values have been written to the registry at HKLM\software\policies\MyProgram . If they have, I assume that GPO has been applied and I use this location to read

Delphi: How to calculate the SHA hash of a large file

十年热恋 提交于 2020-01-01 02:48:09
问题 Hi I need to generate a SHA over a 5 Gig file Do you know of a non string based Delphi library that can do this ? 回答1: You should use DCPcrypt v2 and read your file buffered and feed the SHA hasher with the buffer until you've read the complete 5GB file. If you want to know how to read a large file buffered, see my answer about a file copy using custom buffering. so in concept (no real delphi code!): function GetShaHash(const AFilename: String) begin sha := TSHAHasher.Create; SetLength(Result

Delphi TQuery save to csv file

纵然是瞬间 提交于 2020-01-01 02:48:05
问题 I want to export content of a TQuery to a CSV file without using a 3d part component(Delphi 7). From my knowledge this can not be accomplished with Delphi standard components. My solution was to save the content in a StringList with a CSV format, and save it to a file. Is there any comfortable solution? PS:I don't want to use JvCsvDataSet or any component. Question is: can this be accomplished only with Delphi 7 or higher standard components? Thank you in advance! 回答1: Of course it can. You