tobject

Threadlist of TObject with Delphi - How to populate?

╄→гoц情女王★ 提交于 2019-12-24 12:36:22
问题 From my limited knowledge about this subject, the following code should work. But I have not the expected result: type TClient = class(TObject) Host: String; end; var Clients: TThreadList; const Hosts: Array[0..5] of String = ('HOST1', 'HOST2', 'HOST3', 'HOST4', 'HOST5', 'HOST6'); var I: Integer; List: TList; Client: TClient; begin try for I := Low(Hosts) to High(Hosts) do begin Client := TClient.Create; with Client Do try Host := Hosts[I]; List := Clients.LockList; try Clients.Add(Client);

Invalid typecast: convert record to tobject on 64-bit platform

人走茶凉 提交于 2019-12-23 10:14:21
问题 it works on 32-bit platform.but not 64-bit here is the exzample TVerbInfo = packed record Verb: Smallint; Flags: Word; end; var VerbInfo: TVerbInfo; strList : TStringList; verb : Smallint; flags : Word; begin strList := TStringList.create(); ..... verbInfo.verb := verb; verbInfo.flags := flags; strList.addObject('verb1',TObject(VerbInfo)); //invalid typecast happened here end; can anyone help me? thank you very much 回答1: You can try something like this: function MakeVerbInfoObject(const

Delphi FireMonkey TListBox AddObject exception on Android

为君一笑 提交于 2019-12-04 02:01:43
问题 I'm having a problem adding a TObject value to a FireMonkey TListBox in Delphi 10.0 Seattle. An exeception is raised when casting an Integer variable to a TObject pointer. I tried the cast to TFmxObject with no success. On Windows, the cast works like a charm, but on Android it raises the exception. Here is my code: var jValue:TJSONValue; i,total,id: integer; date: string; begin while (i < total) do begin date := converteDate(jValue.GetValue('date' + IntToStr(i), '')); id := StrToInt(jValue

Delphi FireMonkey TListBox AddObject exception on Android

こ雲淡風輕ζ 提交于 2019-12-01 12:52:29
I'm having a problem adding a TObject value to a FireMonkey TListBox in Delphi 10.0 Seattle. An exeception is raised when casting an Integer variable to a TObject pointer. I tried the cast to TFmxObject with no success. On Windows, the cast works like a charm, but on Android it raises the exception. Here is my code: var jValue:TJSONValue; i,total,id: integer; date: string; begin while (i < total) do begin date := converteDate(jValue.GetValue('date' + IntToStr(i), '')); id := StrToInt(jValue.GetValue('id' + IntToStr(i), '')); ListBox1.Items.AddObject(date, TObject(id)); i := i + 1; end; end;

cast TObject using his ClassType?

吃可爱长大的小学妹 提交于 2019-12-01 03:48:26
问题 how can i make my code to work ? :) i`ve tried to formulate this question but after several failed attempts i think you guys will spot the problem faster looking at the code than reading my 'explanations'. thank you. setCtrlState([ memo1, edit1, button1], False); _ procedure setCtrlState(objs: array of TObject; bState: boolean = True); var obj: TObject; ct: TClass; begin for obj in objs do begin ct := obj.ClassType; if (ct = TMemo) or (ct = TEdit) then ct( obj ).ReadOnly := not bState; //

Delphi array initialization

淺唱寂寞╮ 提交于 2019-11-30 17:14:00
I currently have this, and it sucks: type TpointArray = array [0..3] of Tpoint; class function rotationTable.offsets(pType, rotState, dir: integer): TpointArray; begin Result[0] := point(1, 1); Result[1] := point(1, 2); Result[2] := point(1, 1); Result[3] := point(1, 1); end; but instead, i want to do something like this: class function rotationTable.offsets(pType, rotState, dir: integer): TpointArray; begin Result := [Point(1,1), Point(1,2), Point(1,1), Point(1,1)]; end; However, on compilation, it complains that the [1, 2, 3, 4] syntax can only work for Integers. Is there a way to

What data does a TObject contain?

a 夏天 提交于 2019-11-30 15:07:28
问题 TObject.InstanceSize returns 8, yet TObject doesn't declare any data members. According to the implementation of TObject.ClassType, the first 4 bytes can be explained as a pointer to the object's TClass metadata. Anyone know what the other 4 bytes of overhead are there for? EDIT: Apparently this is specific to D2009. In older versions, it's only 4 bytes. 回答1: In Delphi 2009, there is the ability to have a reference to a synchronization monitor. See: class function TMonitor.GetFieldAddress

Delphi array initialization

房东的猫 提交于 2019-11-30 00:42:42
问题 I currently have this, and it sucks: type TpointArray = array [0..3] of Tpoint; class function rotationTable.offsets(pType, rotState, dir: integer): TpointArray; begin Result[0] := point(1, 1); Result[1] := point(1, 2); Result[2] := point(1, 1); Result[3] := point(1, 1); end; but instead, i want to do something like this: class function rotationTable.offsets(pType, rotState, dir: integer): TpointArray; begin Result := [Point(1,1), Point(1,2), Point(1,1), Point(1,1)]; end; However, on