Delphi

Porting a C array declaration to Delphi

倾然丶 夕夏残阳落幕 提交于 2019-12-31 01:55:14
问题 In C, I can declare and initialize an char array like this: char arg[10] = "ANY"; Is there any short syntax to do the same in delphi? 回答1: A constant: const arg: array[0 .. 9] of AnsiChar = 'ANY'; A local variable: var arg: array[0 .. 9] of AnsiChar; ... arg := 'ANY'; A global variable: var arg: array[0 .. 9] of AnsiChar = 'ANY'; 回答2: something like this: var arg1: string = 'any'; or var arg2: packed array[0..9] of char = 'any'; if you really want an array starting with index 0, as in C, or

Delphi Reverse order of bytes

Deadly 提交于 2019-12-31 01:50:33
问题 I have been trying to write a function that takes two pointers (an input and an output) and writes the bytes from the input into the output in reverse order. So far I have not been able to make it work correctly. procedure ReverseBytes(Source, Dest: Pointer; Size: Integer); var Index: Integer; begin Move(Pointer(LongInt(Source) + Index)^, Pointer(LongInt(Dest) + (Size - Index))^ , 1); end; Can anyone please suggest a better way of doing this. Thanks. 回答1: procedure ReverseBytes(Source, Dest:

Pass a multidimensional array as a parameter in Delphi

寵の児 提交于 2019-12-31 01:49:07
问题 I'd like to pass a multi-dimensional array to a constructor like so: constructor TMyClass.Create(MyParameter: array of array of Integer); begin LocalField := MyParameter; end; Where LocalField is an array of array of Integer. However the above code won't compile ('Identifier expected but ARRAY found'). Could somebody explain to me why this is wrong? I tried reading up on open, static and dynamic arrays but have yet to find something that works. Is there a way to fix it without changing the

Designintf.dcu not found in custom component

北城余情 提交于 2019-12-31 01:22:05
问题 I am here converting some customize delphi component to latest delphi xe5. I already build it in delphi xe5 ide and where desgninf i replaced with designintf and design editor. i also include designide.dcp in reference . it build and install sucessfully . but there some packages while i try to use and complie error like designinf.dcu not found come . i study on internet for solution as after delphi 6 their delphi not redistributed their design time packges. but because it in delphi 5 and

Delphi: TImage.Create causes Access violation

。_饼干妹妹 提交于 2019-12-31 00:58:11
问题 I apologize in advance for a newbie question, but why do I get "Access violation" error with the code below (on the "Create(SelectorForm);" line)? I tried using the main form as the owner, but it didn't make any difference. var SelectorForm: TSelectorForm; ArrayOfImages: Array [1..10] of TImage; implementation procedure TSelectorForm.FormCreate(Sender: TObject); var Loop: Byte; begin for Loop := 1 to 10 do begin with ArrayOfImages[Loop] do begin Create(SelectorForm); end; end; end; 回答1: The

Closing modal dialog in delphi firemonkey mobile application (Android)

最后都变了- 提交于 2019-12-31 00:45:06
问题 I am having the dandiest time trying to figure out why my modal form will not close! Using Delphi XE-5 and FireMonkey Mobile App (Android), i followed the the info "ShowModal Dialogs in FireMonkey Mobile Apps" for demo purposes, i created a new Firemonkey Mobile delphi application and added a secondary firemonkey mobile form. From the main form, i use the code from the article: procedure TForm1.Button1Click(Sender: TObject); var Form2: TForm2; begin Form2 := TForm2.Create(nil); Form2

How to load and display tiff images in TImage control?

一曲冷凌霜 提交于 2019-12-31 00:39:29
问题 I am currently working on Delphi XE2 trial version. I want to load and display TIFF images in TImage control without using any third party component/library. I tried below code but it is not woking for me. Procedure TForm1.Button1Click(Sender: TObject); Var OleGraphic : TOleGraphic; fs : TFileStream; Source : TImage; BMP : TBitmap; Begin Try OleGraphic := TOleGraphic.Create; fs := TFileStream.Create('c:\testtiff.dat', fmOpenRead Or fmSharedenyNone); OleGraphic.LoadFromStream(fs); Source :=

Fast way to split a string into fixed-length parts in Delphi

江枫思渺然 提交于 2019-12-31 00:31:07
问题 I need to split a string to a TStringList with fixed-length sub-strings. Currently I use: procedure StrToStringList(ASource: string; AList: TStrings; AFixedLen: Integer); begin Assert(Assigned(AList)); while Length(ASource) > AFixedLen do begin AList.Add(LeftStr(ASource, AFixedLen)); Delete(ASource, 1, AFixedLen); end; AList.Add(ASource); end; This works, but seems to be slow. Any better / faster idea? Edited: Profiling of the results : The speed gain is quite impressive. Here are the results

RadioButtons save last checked instead of desired one when form displayed again

不打扰是莪最后的温柔 提交于 2019-12-30 23:23:13
问题 I have some TRadioButton s on Form2 and call Form2 from Form1 with this code: procedure TForm1.btnCallForm2Click(Sender:TObject) begin Form2.RadioButton2.Checked:= true; Form2.ShowModal; end; If user clicked btnCallForm2 , Form2 will be displayed, then user clicks RadioButton3 and closes the form, and then reopen it by clicking btnCallForm2 again. Now Form2 displayed again but RadioButton3 is checked instead of RadioButton2 . Q: What is this behavior, is it a bug? How to set checked my

Dealing with circular strong references in Delphi

我的梦境 提交于 2019-12-30 18:33:52
问题 I got two classes (in my example TObject1 and TObject2) which know each other via interfaces (IObject1, IObject2). As you probably know in Delphi this will lead to a memory leak as both reference counter will always stay above zero. The usual solution is declaring one reference as weak. This works in most cases because you usually know which one will be destroyed first or don't necessarily need the object behind the weak reference once it is destroyed. This said I tried to solve the problem