Jump to content

How to set the service port in a ini file?


55143681

Recommended Posts

Unit CONFIGURACIONPARMS;
 
interface
var
  G_DBSERVER      :string;
  G_DBNAME        :string;
  G_DATABASE      :string;
  G_USUARIODB     :string;  // USUARIO COMUN TOMADO DE LA CONFIGURACION
  G_PASSWDB        :string;  // tomado de la configuracion
  G_Usuario       :String;
  g_PassW         :string;
  G_ROLE          :string;
  G_Port          :Integer ;
  g_ExtRoot       :string;
  G_CacheFolder  :string;
  G_Title         :string;
  g_LogoCompania  :string;
  g_LogoLogin     :string;
  g_Theme         :string;
{}
  P_USUARIO       :STRING;
  O_CONO          :string;
  O_CLIENTE       :string;
  O_CLIENTESHP    :string;
 
  Procedure SET_INICIAR_VALORES;
 
implementation
 
Procedure SET_INICIAR_VALORES;
Var
  W_Null:Variant;
BEGIN
  //P_RECURSO    :='';
End;
 
END.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ARCHIVO DE CONFIGURACION 

  Configuracion.cfg

 
 
[user]
USUARIO=SERVINETWEB
PASSW=SERVINETWEB
ROLE=USUARIOS
 
[server]
SERVER=192.168.1.115    <-- NO SE USA
 
[Database]
DBSERVER=192.168.1.115
DBNAME=127.0.0.1:E:\__DISCO C TOSHIBA\SERVINET_XE10_BERLIN\SERVINETDB-2017.FDB
 
[Logos]
 
LOGO_LOGIN=E:\__DISCO C TOSHIBA\SERVINETWEB\apix_logo Compania.jpg
LOGO_COMPANIA=E:\__DISCO C TOSHIBA\SERVINETWEB\apix_logo Compania.jpg
 
LOGO_LOGIN_CDLG=C:\SERVINETWEB\LOGO_CDLG.JPG
LOGO_COMPANIA_CDLG =C:\SERVINETWEB\LOGO_CDLG3.JPG
 
 
[Logos Otros]  <-- NO SE USA
XLOGO_COMPANIA=C:\SERVINETWEB\Logo_Organizacion_hercules_Compania.jpg
XLOGO_LOGIN=E:\__DISCO C TOSHIBA\SERVINETWEB\Logo_Organizacion_hercules_Compania_LOGIN.jpg
 
LOGO_COMPANIA_apix=C:\SERVINETWEB\apix_logo Compania.jpg
LOGO_LOGIN=C:\SERVINETWEB\apix_logo.jpg
LOGO_COMPANIA_INTERLLANTAS=logoInterllantas.png
LOGO_LOGIN_INTERLLANTAS   =logoInterllantas.png
 
[Licencias]
LICENCIA1=XXXXXXX
LICENCIA2=YYYYYY
[serverModule]
Port=8077
ExtRootX=C:\SERVINET2014 X2\DELPHIWEB\ext-4.2.2.1144\ 
CacheFolder=\cache 
ExtRoot=C:\Program Files (x86)\FMSoft\Framework\uniGUI\ext-4.2.5.1763
Title=SERVINETWEB@LOGISTICASOFT
[MAINMODULE]
BackGroundPicture=Tortas-de-cumpleanos-vectorizadas.jpg
Theme=default
Theme_blue=blue
Theme_gray_gray
Theme_neptune=neptune
Theme_access=access
 IniFile.ReadString('ServerModule' , 'ExtRoot', ' ') ;
 
****  FIN ARCHIVO DE CONFIGURACION ********
 
 
EN SERVER MODULE
 
implementation
 
{$R *.dfm}
 
uses
  UniGUIVars ,inifiles , CONFIGURACIONPARMS;    // <-------- incluye unidad
 
 
 
procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
begin
  LEER_CONFIGURACION;
end;
 
 
procedure TUniServerModule.LEER_CONFIGURACION;
var
  IniFile  : TIniFile;
  w_F      :TextFile;
  W_CONFIGURACION:string ;
  W_DIR    :string;
  W_String:string;
  W_ERROR:STRING;
begin
 
     FormatSettings.shortdateformat         := 'yyyy/MM/dd';     //2008/04/16
     FormatSettings.ShortTimeFormat         := 'HH:MM';
     FormatSettings.LongTimeFormat          := 'HH:MM:SS.zzzz';
     FormatSettings.DecimalSeparator        := '.';
     FormatSettings.ThousandSeparator       := ',';
     FormatSettings.dateSeparator           := '-';
     FormatSettings.timeSeparator           := ':';
 
 
 W_DIR := ExtractFilePath(UniFullPath);
 W_DIR := UniServerModule.StartPath;
 
 W_CONFIGURACION :=   W_DIR + 'Configuracion.cfg' ;    //  <------------------------leer configuracion externa    
 
   TRY
 
    IniFile    := TIniFile.Create( W_CONFIGURACION );
 
   EXCEPT
     on E : Exception do begin
      W_ERROR:= E.Message;
     end;
   END;
 
   // LEER PARAMETROS
 
    CONFIGURACIONPARMS.G_DBSERVER     := IniFile.ReadString('Database' , 'DBSERVER', ' ') ;
    CONFIGURACIONPARMS.G_DBNAME       := IniFile.ReadString('Database' , 'DBNAME', ' ') ;
    CONFIGURACIONPARMS.G_DATABASE     := CONFIGURACIONPARMS.G_DBNAME;
 
    CONFIGURACIONPARMS.g_USUARIODB    := IniFile.ReadString('User' , 'USUARIO', ' ') ;
    CONFIGURACIONPARMS.g_PASSWDB      := IniFile.ReadString('User' , 'PASSW', ' ') ;
    CONFIGURACIONPARMS.g_ROLE         := IniFile.ReadString('User' , 'ROLE', ' ') ;
 
 
    CONFIGURACIONPARMS.g_LogoCompania := IniFile.ReadString('LOGOS' , 'LOGO_COMPANIA', ' ') ;
    CONFIGURACIONPARMS.g_LogoLogin    := IniFile.ReadString('LOGOS' , 'LOGO_LOGIN', ' ') ;
 
    CONFIGURACIONPARMS.g_port         := StrToInt(IniFile.ReadString('ServerModule' , 'Port', ' ')) ;
    CONFIGURACIONPARMS.G_ExtRoot      := IniFile.ReadString('ServerModule' , 'ExtRoot', ' ') ;
    CONFIGURACIONPARMS.G_CacheFolder  := IniFile.ReadString('ServerModule' , 'CacheFolder', ' ') ;
 
    CONFIGURACIONPARMS.G_TITLE        := IniFile.ReadString('ServerModule' , 'Title', ' ') ;
    CONFIGURACIONPARMS.G_Theme        := IniFile.ReadString('ServerModule' , 'g_Theme', ' ') ;
 
 
// SET PARAMETROS
    UniServerModule.title             := G_TITLE;
    UniServerModule.title             := CONFIGURACIONPARMS.G_TITLE ;
    UniServerModule.Port              := G_PORT;
end;
 
 
Link to comment
Share on other sites

Make an ini-file called setup.ini in the same directory as your app:

[Setup]
Port=8088

Then add this in your servermodule:

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
var Ini: TIniFile;
begin	
  ServerRoot:=extractfilepath(GetModuleName(HInstance));
  Ini := TIniFile.Create(ServerRoot+'setup.ini');
  try
    Port := strToIntDef(Ini.ReadString('Setup', 'Port', '8088'), 8088);
  finally
    Ini.Free;
  end;	
end;
Link to comment
Share on other sites

Thanks to everyone.I know how to use a ini file,my question is when I set the serverPort,I have a error.

#pragma startup __RegisterServerModuleClass
void __fastcall TUniServerModule::UniGUIServerModuleCreate(TObject *Sender)
{
UniServerModule()->Port=8088;
}
 
the error is:
Unresolved external '__fastcall Uniguiserver::TUniGUIServerModule::setPortA(unsigned short)' referenced from "d:\testsetport\win32\debug\servermodule.obj"
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...