Delphi - trabajar sin conexion en datasnap

 
Vista:
sin imagen de perfil
Val: 3
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

trabajar sin conexion en datasnap

Publicado por caruso (15 intervenciones) el 31/03/2015 19:07:02
Estoy realizando mi aplicacion cliente servidor, y el caso es que hice un state-less(por si no hay internet), en realidad una vez por dia al iniciar la aplicacion guardo un fichero xml de productos y otro de clientes (esto es solo un TPV), lo mismo con el ticket. Estos luego son enviados. Para lo mismo en el Source del .exe (ejecutable), primero creo el clientmodule que conecta al datasnap.

Trabajo con mysqlWorkbench y delphi. Pero tambien uso componenetes ZeosLib para traer datos, tengo entendido zeoslib accede directamente a la base de datos, es decir no tengo procedimientos en el server para cargar productos y clientes.

Entonces la aplciacion larga un cartel "trabajando sin conexion" y se abre el form sin problemas, amenos que el servicio de mysql (mysqld.exe) no este corriendo. entonces dice project1.exe ha detectado un problema y debe cerrarse.

En el source del exe:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Iceberg Classico');
 
 
  Application.CreateForm(TClientModule1, ClientModule1);
  ScreenWidth:=screen.DesktopWidth;
  ScreenHeight:=screen.DesktopHeight;
  Application.CreateForm( TForm2, Form2);
 // Unit9.ScaleForm(Form2,ScreenWidth, ScreenHeight);
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm3, Form3);
  Application.CreateForm(TForm4, Form4);
 // Unit9.ScaleForm(Form4,ScreenWidth, ScreenHeight);
  Application.CreateForm(TForm5, Form5);
  Application.CreateForm(TCLIENTES, CLIENTES);
  Application.CreateForm(TForm7, Form7);
  Application.CreateForm(TForm8, Form8);
  Application.Run;

y en el "OnCreate" del clientmodule(trato de conectar sino cargo los ultimos xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
procedure TClientModule1.DataModuleCreate(Sender: TObject);
 
var
admin:TIniFile;
nombre,destino,hoy,hoycli:string;
i,x:integer;
ultimo:string;
fecha:TDateTime;
begin
 
admin:=TIniFile.Create(ExtractFilePath(Application.ExeName )+ 'caja.ini');
 try
    with ClientModule1.SQLConnection1 do
          begin
            Close;
                Params.Values['DriverName']:=admin.ReadString('admin','DriverName','');
                Params.Values['HostName']:=admin.ReadString('admin','HostName','');
                Params.Values['Port']:=admin.ReadString('admin','Port','211');
 
 
                Connected:=True;
          end;
 
      with ClientModule1.ZConnection1  do
        begin
 
          Catalog := admin.ReadString('admintablas','Catalog','');
          Database := admin.ReadString('admintablas','Database','');
          HostName := admin.ReadString('admintablas','HostName','');
          Password := admin.ReadString('admintablas','Password','');
          Port := admin.ReadInteger('admintablas','Port',3306);
          Protocol := admin.ReadString('admintablas','Protocol','');
          User := admin.ReadString('admintablas','User','');
          Connected:=True;
 
        end;
           begin
      for i := 0 to ComponentCount -1 do
      begin
        if Components[i] is TZTable then
 
        TZTable(Components[i]).Active :=True;
 
        end;
    for i := 0 to ComponentCount -1 do
    begin
    if Components[i] is TZQuery then
      TZQuery(Components[i]).Active :=True;
     end;
           end;
      if (ClientModule1.SQLConnection1.Connected) then
  begin
    hoy:=ExtractFilePath(Application.ExeName)+ 'productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
    hoycli:=ExtractFilePath(Application.ExeName)+ 'clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
    if FileExists(hoy) then
      begin
        ShowMessage('datos ya copiados');
      end
      else
          begin
        with ClientModule1.cdsprod do
          begin
            Active:=True;
            nombre:='productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
            destino:=ExtractFilePath(Application.ExeName) + nombre;
            ClientModule1.cdsprod.SaveToFile(destino,dfXMLUTF8);
 
          end;
         end;
        if FileExists(hoycli) then
          begin
            ShowMessage('datos ya copiados');
          end
          else
          begin
          with cdsclientes do
            begin
              Active:=True;
              nombre:='clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
              destino:=ExtractFilePath(Application.ExeName) + nombre;
              ClientModule1.cdsclientes.SaveToFile(destino,dfXMLUTF8);
 
            end;
          end;
 
 
  end;
except
 
       begin
 
          if FileExists(hoy) then
              begin
              cdsprod.LoadFromFile(hoy);
              ShowMessage('archivo de hoy');
              end
      else
            begin
              while not (FileExists(ultimo)) do
 
                    begin
                      ultimo:=ExtractFilePath(Application.ExeName)+ 'productos'+ FormatDateTime('dd-mm-yyyy',IncDay(Now,x)) + '.xml';
                      Dec(x);
                    end;
            end;
       end;
               ShowMessage('trabajando sin conexion');
 
       end;
 
 
end;

Si es el servicio de mysql pueden ser los componentes zeos que de haber conexion los conecto?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 65
Oro
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

trabajar sin conexion en datasnap

Publicado por E.T. (1244 intervenciones) el 07/04/2015 01:39:49
Por que no intentas ejecutar tu aplicación en debug desde delphi, ahi te daria el error, pues lo que comentas no dice nada del error.
Donde te sale el error en tu pc de desarrollo, o en una pc de uso normal?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar