Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Recent

jan741

• New Member
• Posts: 15
« on: December 09, 2022, 05:16:53 pm »
Identifier deproc not found on function-call(see comment in code below). Exactly based on this example. https://wiki.lazarus.freepascal.org/Asynchronous_Calls

What's going wrong?

Code: Pascal  [Select][+][-]
1. unit Unit1;
2.
3. {\$mode objfpc}{\$H+}
4.
5. interface
6.
7. uses
8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
9.   StdCtrls, dbugintf, LazLoggerBase, pingsend;
10.
11. const
13.   stringlen = 10000;
14.
15. type
16.
17.   { TForm1 }
18.
19.   TForm1 = class(TForm)
20.     Button1: TButton;
21.     Button2: TButton;
22.     procedure Button1Click(Sender: TObject);
23.     procedure Button2Click(Sender: TObject);
24.
25.   private
26.     { private declarations }
27.     procedure deproc(input: PtrInt);
28.   public
29.     { public declarations }
30.   end;
31.
32.   myrec = record
33.     i : longint;
34.     s : string;
35.   end;
36.
37.   Pmyrec = ^myrec;
38.
39. var
40.   Form1: TForm1;
41.   finished : longint;
42.   y : longint;
43.   nr : integer;
45.   thri : ptrint;
46.
47. implementation
48. {\$R *.lfm}
49.
50. { TForm1 }
51.
52.
53. function f(p : Pointer) : ptrint;
54.
55. var
56.   s : ansistring;
57.   thisrec : myrec;
58. begin
59.   thisrec := Pmyrec(p)^;
60.   Writeln('thread ', longint(thisrec.i), ' started');
61.   thri:=0;
62.   while (thri<stringlen) do
63.     begin
64.     s:=s+'1';
65.     inc(thri);
66.     end;
68.   InterLockedIncrement(finished);
69.   f:=0;
70.   nr:=10;
71.   Application.QueueAsyncCall(@deproc, nr);  //<--------------------------------------------------------------------------------------- error happening here
72. end;
73.
74. procedure TForm1.Button1Click(Sender: TObject);
75. begin
76.   y:= 1;
77. end;
78.
79. procedure TForm1.Button2Click(Sender: TObject);
80. var
82.   pr: ^myrec;
83.   x : longint;
84. begin
85.    finished:=0;
86.
87.    for x :=1 to threadcount do
88.      begin
89.        r[x].s := ' test ';
90.        r[x].i:=x;
93.      end;
95. end;
96.
97. procedure deproc(input:PtrInt);
98. begin
99.    writeln('async called.');
100. end;
101.
102. end.
« Last Edit: December 09, 2022, 05:21:20 pm by jan741 »

Handoko

• Hero Member
• Posts: 4784
• My goal: build my own game engine using Lazarus
« Reply #1 on: December 09, 2022, 05:51:50 pm »
That line #97, should be:

Code: Pascal  [Select][+][-]
1. procedure TForm1.deproc(input: PtrInt);

howardpc

• Hero Member
• Posts: 4117
« Reply #2 on: December 09, 2022, 05:53:15 pm »
Code: Pascal  [Select][+][-]
1. unit Unit1;
2.
3. {\$mode objfpc}{\$H+}
4. {\$IFDEF MSWINDOWS} {\$apptype console} {\$EndIf}
5.
6. interface
7.
8. uses
9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
10.
11. const
13.     stringlen = 10000;
14.
15. type
16.
17.   TForm1 = class(TForm)
18.     Button2: TButton;
19.     procedure Button2Click(Sender: TObject);
20.   private
21.     procedure deproc(input: PtrInt);
22.   end;
23.
24.
25.   myrec = record
26.       i : longint;
27.       s : string;
28.   end;
29.   Pmyrec = ^myrec;
30.
31. var
32.   Form1: TForm1;
33.   finished, nr: LongInt;
34.
36.   thri : PtrInt;
37.
38. implementation
39.
40. {\$R *.lfm}
41.
42. function f(p: Pointer): PtrInt;
43. var
44.   s: AnsiString = '';
45.   thisrec: myrec;
46. begin
47.   thisrec := Pmyrec(p)^;
48.   Writeln('thread ', thisrec.i, ' started');
49.   thri := 0;
50.   while (thri<stringlen) do
51.     begin
52.     s := s+'1';
53.     Inc(thri);
54.     end;
56.   InterLockedIncrement(finished);
57.   f:=0;
58.   nr:=10;
59.   Application.QueueAsyncCall(@Form1.deproc, nr); // <--------------- error happening here
60. end;
61.
62. procedure TForm1.Button2Click(Sender: TObject);
63. var
65.   pr: ^myrec;
66.   x : longint;
67. begin
68.    finished:=0;
69.    for x :=1 to threadcount do
70.      begin
71.        r[x].s := ' test ';
72.        r[x].i:=x;
75.      end;
77. end;
78.
79. procedure TForm1.deproc(input: PtrInt);
80. begin
81.   WriteLn('async called.');
82. end;
83.
84. end.
« Last Edit: December 09, 2022, 06:44:41 pm by howardpc »

• Hero Member
• Posts: 12898
« Reply #3 on: December 09, 2022, 06:16:22 pm »
The error may be here: longint(thisrec.i). That should be ptrUint not ptrInt. Pointers can not be negative and longint does not work above 32 bit.
« Last Edit: December 09, 2022, 06:18:04 pm by Thaddy »
Who is responsable for that!! The caller or the callee.. Out! ya'll, NOW. In UTC time, please, so maybe Yesterday or tomorrow.

howardpc

• Hero Member
• Posts: 4117
« Reply #4 on: December 09, 2022, 06:46:12 pm »