Found the problem. Wrong Pointer
Hi all,
I am working on a program (win7 32bit, Lazarus 2.0.0). It worked well before. 3 days ago, I decided to do some change(the way to read and write data from RS485). And I got a strange crash "Project raised exception class 'External:SIGSEGV' " At adress 4633A2 whenever I start the program.
what I did when the program starts was:
procedure TFrmMain.FormCreate(Sender: TObject);
var
bRet: boolean = False;
i:integer;
begin
ActivePanel:=@pnZhenKong;
ActiveLabel:=@lbZhenKong;
lbZhenKongClick(Self);
if LoadCmdFile then
log('Load cmd file OK')
else
begin
log('load cmd file fail',clRed);
exit;
end;
if LoadSysFile then
log('load sys file OK')
else
begin
log('load sys file Fail',clRed);
exit;
end;
CreateCiFenXiJiSuanBlock;
CreateShuLiuHuanJingBlock;
CreateFaMenAndKaiGuanBlock;
CreateFenZiBengBlock;
CreateZhenKongJiLED;
CreateLiuLiangJiBlock;
CreateDianYuanBlock;
CreateFuZhuKaiGuan_ShuRuBlock;
CreateFuZhuMoNi_ShuRuBlock;
CreateFuZhuMoNi_ShuChuBlock;
CreateBaTaiWenKongBlock;
CreateBuJinDianJiBlock;
for i:=0 to Length(MyCom)-1 do MyCom[i].Start;
Delay(500);
DJ2HSS442_RC_Init;
end;
I believe something wrong with this procedure. So I did the following:
1. remark all of the code in TFrmMain.FormCreate. The program worked again. no crash.
2. remark all of the lines start from CreateCiFenXiJiSuanBlock. The program worked again. not crash.
3. unmark any line named as "Create...Block", the program crash again! What these procedures named "Create...Block" did was to create some components on the mainform according to the information they read from 'sys.pzwj'. They worked very well before.
4. I unmarked 1 "Create...Block" procedure (any one of them, the result is the same) and debuged the program step by step. It worked well at project file line: Application.CreateForm(TFrmMain, FrmMain); And I can see the components were correctly created and shown on the mainform. Then it crashed at Application.Run;
5. I stepped into Application.Run; and found it crashed at WidgetSet.AppRun(@RunLoop);
I guess I must modified something unconciously which made the dynamic created components can not be shown correctly (If i remark all of the "Create...Block", the program would not crash). But I don't know what I really did.
The dynamic created components include TLabel, TShape, TFloatSpinEdit and some components in package Industrial. I've installed the package industrial. And If I put these component statically on mainform, everything is ok. it crash only when they are created dynamically.
Anyone has suggestion? Thanks for your notice and help!
Senglit