delphi - Forms create same time -



delphi - Forms create same time -

i have 2 forms, , want firstly create main form , if user click button, send variable , create sec form.

but in code, when had started application, tried create 2 form, application crushes because sec form has not parameter yet.

main form call:

procedure tform1.listitemclick(const sender: tobject; const aitem: tlistviewitem); var item: tlistviewitem; begin item:= aitem; zipid:= item.text; form2.show; end;

second form:

var form2: tform2; zipid: string; implementation {$r *.fmx} uses main; procedure tform2.imageclick(sender: tobject); var image: timage; i: integer; begin image:= sender timage; if rects[image.tag-1].fill.color = talphacolorrec.gray begin rects[image.tag-1].fill.color:= talphacolorrec.blue; rects[image.tag-1].tag:= 1; end else begin rects[image.tag-1].fill.color:= talphacolorrec.gray; rects[image.tag-1].tag:= 0; end; end; procedure tform2.formcreate(sender: tobject); var path: string; stream: tbytesstream; z: tzipfile; sr: tsearchrec; dest: tstringlist; i,j: integer; getzipid: string; begin url:= 'http://192.168.1.5:3030/api/db/'; client.baseurl:= url + 'control'; req.method:= trestrequestmethod.rmpost; req.addparameter('getzip', form1.zipid); req.execute; path:= '/storage/emulated/0/'; stream := tbytesstream.create(decodebase64(res.content)); seek //android - system.ioutils.tpath.getdocumentspath + system.sysutils.pathdelim stream.savetofile(path + 'myfile.zip'); z := tzipfile.create; seek z.open(path + 'myfile.zip', zmread); z.extractall(path + 'library'); z.free; end; stream.free; end; if findfirst(path + 'library/'+'*.*', faanyfile, sr) = 0 repeat if extractfileext(sr.name) = '.jpg' dest.add(sr.name); until findnext(sr) <> 0; findclose(sr); setlength(imgs, dest.count); setlength(rects, dest.count); := 0 dest.count-1 begin rects[i]:= trectangle.create(form2); rects[i] begin parent:= flow; width:= 146; height:= 112; margins.left:= 10; margins.right:=10; margins.top:= 5; tag:= 0; fill.color := talphacolorrec.gray end; imgs[i]:= timage.create(form2); imgs[i] begin parent:= rects[i]; bitmap.loadfromfile(path + 'library/'+dest[i]); width:= 146; height:= 112; position.x:= 5; position.y:= 5; onclick:= imageclick; tag:= i+1; end; end; if removedir(system.ioutils.tpath.getdocumentspath + system.sysutils.pathdelim + 'library') showmessage('silindi'); end; end.

i new on delphi, , don't understand why when application starts, create 2 form.

in delphi in project->view source

you have this

program yourprogram; uses forms, utform1 in 'utform1.pas' {tform1}, utform2 in 'utform2.pas' {tform2}; {$r *.res} begin application.initialize; application.mainformontaskbar := true; application.createform(tform1, form1); application.createform(tform2, form2); application.run; end.

remove line application.createform(tform2, form2); first form created @ startup.

then when click button open sec form creat sec form.

procedure tform1.listitemclick(const sender: tobject; const aitem: tlistviewitem); var item: tlistviewitem; frm : tform2; begin item:= aitem; zipid:= item.text; frm := tframe2.create(nil); frm .show; end;

example : // project source code programme project1;

uses forms, unit1 in 'unit1.pas' {form1}, unit2 in 'unit2.pas' {form2}; {$r *.res} begin application.initialize; application.mainformontaskbar := true; application.createform(tform1, form1); // creates first form on start application.run; end. unit unit1; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; type tform1 = class(tform) button1: tbutton; procedure button1click(sender: tobject); private { private declarations } public { public declarations } end; var form1: tform1; implementation uses unit2; {$r *.dfm} procedure tform1.button1click(sender: tobject); var frm : tform2; // create tform2 object begin frm := tform2.create(nil); // create object frm.show; // show object ( in our case form ) end; end.

delphi

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -