Jump to content

application settings


leons

Recommended Posts

Right, and put it in the servermodule, and in the mainmodule onCreate as well if you need to.

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
var f:textfile;
    hostLine, portLine, dbLine, dbPortLine:string;
    cmdStr:string;

procedure ExploreWeb(page:PChar);
var Returnvalue: integer;
begin
  ReturnValue := ShellExecute(0, 'open', page, nil, nil,SW_SHOWNORMAL);
  if ReturnValue <= 32 then
     begin
     case Returnvalue of
          0 : MessageBox(0,'Error: Out of memory','Error',0);
          ERROR_FILE_NOT_FOUND: MessageBox(0,'Error: File not found','Error',0);
          ERROR_PATH_NOT_FOUND: MessageBox(0,'Error: Directory not found','Error',0);
          ERROR_BAD_FORMAT    : MessageBox(0,'Error: Wrong format in EXE','Error',0);
     else
          MessageBox(0,PChar('Error Nr: '+IntToStr(Returnvalue)+' inShellExecute'),'Error',0)
     end;
  end;
end;

begin
  ServerRoot:=extractfilepath(GetModuleName(HInstance));

  //read setup text file
  try
    assignfile(f, ServerRoot+'files/setup.txt');
    reset(f);
    readln(f, hostLine);
    readln(f, portLine);
    readln(f, dbLine);
    readln(f, dbPortLine);
    closefile(f);
  except
    on E:Exception do ;
  end;

  case sslSetup of
    true: begin
      ssl.Enabled:=true;
      port:=443;
    end;
    false:begin
      ssl.Enabled:=false;
      port:=strtointdef(portLine, 8077);
    end;
  end;

  //connect db
  try
  with myDb do begin
    username:='user';
    userpassword:='pass';
    host:=hostLine;
    databasename:=dbLine;
    port:=strtointdef(dbPortLine, 3307);
    open;
  end;
  except
    on E:Exception do ;
  end;

  //load db setup data
  try
    loadSetup;
  except
    on E:Exception do ;
  end;

  //set app title
  title:=myLoadedSetupTitle;

  //close this db connection
  myDb.close;

  //autostart if standalone
  if self.StandAloneServer then begin
    cmdStr:='http://localhost:'+portLine;
    ExploreWeb(pchar(cmdStr));
  end;
end;
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...