Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Datamodule + intraweb + access violation (https://www.clubdelphi.com/foros/showthread.php?t=15340)

geovany 19-10-2004 18:55:54

Datamodule + intraweb + access violation
 
creo k con el titulo les explico cual es mi problema tengo una aplicacion intraweb y trato de accesas a Bd mediante BDE, tengo todo en un datamodule y al momento de tratar de accesar a los datos me marca un erroe de access violation y si lo pongo en la misma pagina me lo ejecute bien sin ningun error. Por ahi lei algo que no se podía hacer eso pero no decia como resolverlo asi que si alguien sabe como hacerlo se lo agradeceria, bueno pues muchas gracias de antemano

pnsd_89 30-03-2015 17:52:19

Hola en un ejemplo vi que hay que crear el DM en modo de ejecución junto con el oncreate del UserSeccion. ahora estoy investigando como hacer para hacerlo desde el formulario y no desde el userseccion ya que tendre varios DM y no quiero crearlos todos a la vez

pnsd_89 30-03-2015 17:53:14

ahora me fije que tu publicacion fue del 2004 jaja ¿Lo pudiste resolver?

TrUnkS 30-03-2023 22:06:20

Lo ideal es tener varios DataModules en la misma aplicación, de modo que pongas el componente de conexión solo y abandonado en el UserSession (FDConnection). Los otros componentes FDQuery los pongas en cada DataModulo, y que cada formulario IWForm este asociado a un DataModulo. Entonces quedaría así:

El UserSession:

Código Delphi [-]
unit UserSessionUnit;

{
  This is a DataModule where you can add components or declare fields that are specific to 
  ONE user. Instead of creating global variables, it is better to use this datamodule. You can then
  access the it using UserSession.
}
interface

uses
  IWUserSessionBase, SysUtils, Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
  FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
  FireDAC.Phys.MSSQLDef, FireDAC.VCLUI.Wait, Data.DB, FireDAC.Comp.Client;

type
  TIWUserSession = class(TIWUserSessionBase)
    FDConnectionDB: TFDConnection;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

end.

El Módulo de datos:

Código Delphi [-]
unit DMFormLOGIN;

interface

uses
  System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Data.DB,
  FireDAC.Comp.DataSet, FireDAC.Comp.Client;

type
  TIWDMFormLOGIN = class(TDataModule)
    FDQueryTEAM: TFDQuery;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  IWDMFormLOGIN: TIWDMFormLOGIN;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

uses ServerController;

{$R *.dfm}

procedure TIWDMFormLOGIN.DataModuleCreate(Sender: TObject);
begin
 FDQueryTEAM.Connection := UserSession.FDConnectionDB;
end;

end.

Y el Formulario:

Código Delphi [-]
unit FormLOGIN;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, DMFormLOGIN;

type
  TIWFormLOGIN = class(TIWAppForm)
    procedure IWAppFormCreate(Sender: TObject);
    procedure IWAppFormDestroy(Sender: TObject);
    procedure IWAppFormShow(Sender: TObject);
  private
    IWDMFormLOGIN: TIWDMFormLOGIN;
  public
  end;

implementation

{$R *.dfm}


procedure TIWFormLOGIN.IWAppFormCreate(Sender: TObject);
begin
 if IWDMFormLOGIN = nil then // se puede omitir esta linea
  IWDMFormLOGIN := TIWDMFormLOGIN.Create(Self);
end;

procedure TIWFormLOGIN.IWAppFormDestroy(Sender: TObject);
begin
 if Assigned(IWDMFormLOGIN) then // se puede omitir esta línea
  FreeAndNil(IWDMFormLOGIN);
end;

procedure TIWFormLOGIN.IWAppFormShow(Sender: TObject);
begin
 IWDMFormLOGIN.FDQueryTEAM.Open;
end;

initialization
  TIWFormLOGIN.SetAsMainForm;

end.


La franja horaria es GMT +2. Ahora son las 08:36:38.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi