Delphi edition Legendary Engine Learning Rookie (APPLEM2)-06

Source: Internet
Author: User

The engine source code of learning temporarily put down for a few days, because need to master some process processing aspects of the message, before the start service process in the Gamecenter a good thought, the service startup process is taken out separately, originally is the main interface process to judge processing start, good long code, Finally refined out a generic startup process, the process of stopping the service and this is similar.

{functions that run external programs}functionRunprogram (varPrograminfo:tprogram; Shandle:string; dwwaittime:longword): Longword;varStartupinfo:tstartupinfo; Scommandline:string; Scurdirectory:string;beginResult:=0; Fillchar (Startupinfo, SizeOf (Tstartupinfo), #0);  Getstartupinfo (STARTUPINFO); Scommandline:= Format ('%s%s%s %d%d', [Programinfo.sdirectory, Programinfo.sprogramfile, Shandle, Programinfo.nmainformx, ProgramInfo.nMainFormY])  ; Scurdirectory:=programinfo.sdirectory; if  notCreateProcess (Nil,//Lpapplicationname,PChar (Scommandline),//lpCommandLine,    Nil,//Lpprocessattributes,    Nil,//Lpthreadattributes,True//bInheritHandles,    0,//dwCreationFlags,    Nil,//Lpenvironment,PChar (Scurdirectory),//Lpcurrentdirectory,Startupinfo,//Lpstartupinfo,Programinfo.processinfo) Then  begin //lpprocessinformationResult: =GetLastError (); End;  Sleep (Dwwaittime); //WaitForInputIdle (programinfo.processinfo.hprocess,infinite);End;{General Start-up process, rungate can write one more, overload a bit on the line}procedureStartgametimer (var {I left this out before.}Server:tprogram; Shandle:string);varNretcode:integer;begin  ifServer.bogetstart Then  begin     CaseServer.btstartstatus of      0:        begin          //CloseHandle (dbserver.processhandle);          {run DBServer, return 0 indicates successful run}nRetCode:= Runprogram (Server, Shandle,0); ifnRetCode =0  Then          begin            {Run successfully writes the run flag to 1 (starting)}Server.btstartstatus:=1; {returns the DBServer window handle (shows DBServer)}Server.processhandle:=openprocess (process_all_access, False, Server.ProcessInfo.dwProcessId); //frmmain.mainoutmessage (inttostr (server. ProcessHandle));          End          Else          begin          {Otherwise, the error message is displayed, GetLastError is called}ShowMessage (IntToStr (nRetCode)); End;        Exit; End; 1:        begin //If the status is 1, it has not started to complete .          //server.btstartstatus:=2;Exit; End; End; End;End;

Because the foundation is not solid, just this one processing process let me toss for nearly a week, finally remembered to breakpoint debugging, tracking variables found that the inherited main process started the child process handle and the detected handle is not the same, finally found that the Var declaration is missing, should be invoked by reference, Perhaps Delphi inside also should call so, use is the variable is changed after the value, but still can, finally know oneself study process of what insufficient, foundation still is important, before learn Foundation not how to notice this, use to discover originally very simple thing was I think of incredibly complex, For this I shifted attention to learn a few days INI file read and write, I wrote the setion and value traversal function, the results see the VCL inside there are ready-made things, but did not waste events, at least know the basic structure of the INI and processing methods, although their own writing a bit verbose, but it is always their own realization, Oneself up a bit, the next study should enter the message processing stage, DBServer first put, to go back to gamecenter things thoroughly understand and continue, I found on such an engine control contains so many knowledge points, need me to consolidate, again for their refueling.

Delphi edition Legendary Engine Learning Rookie (APPLEM2)-06

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.