Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-08-2010
Avatar de julyus
julyus julyus is offline
Miembro
 
Registrado: jul 2006
Ubicación: IN TO PLACES COLOMBIA AND EE.UU
Posts: 121
Poder: 18
julyus Va por buen camino
Question pregunta hace rato no programo en delphi?

tengo una preguntota de 100000 dollares se pueden crear dos clases en un mismo form o datamodulo ?? gracias por la respuesta
Responder Con Cita
  #2  
Antiguo 03-08-2010
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Julyus.

Si.

Siempre que las clases no tengan el mismo nombre. si no te va dar error de identificador redeclarado.

Es decir que podés hacer:
Código:
type
   Clase1 = class
   end;
   Clase2 = class
   end;
   ClaseN = class
   end;
Pero no:
Código:
type 
    Clase1 = class
    end;
    Clase1 = class  // identifier redeclarer 'clase1'
    end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 03-08-2010 a las 02:05:31.
Responder Con Cita
  #3  
Antiguo 03-08-2010
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Casi me olvido !!!!


Donde me depositas los u$s 100000 ???


Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #4  
Antiguo 03-08-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.309
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Basta con que te des una vuelta por el directorio de la VCL (normalmente en: "c:\Archivos de programa\Borland\Delphi6\Source\Vcl\" o similar) y mires alguno de los ficheros.

StdCtrls.pas, por ejemplo, no sólo tiene más de 1 clase, sino que tiene todas (o casi todas) las clases de los componentes de la paleta Standard de Delphi.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #5  
Antiguo 03-08-2010
Avatar de julyus
julyus julyus is offline
Miembro
 
Registrado: jul 2006
Ubicación: IN TO PLACES COLOMBIA AND EE.UU
Posts: 121
Poder: 18
julyus Va por buen camino
Question este el el codigo a ver que handa mal aca

hola el problema se me presenta en las clases TFixedConnectionPool y TCleanupThread si ven una necesita de la otra y si las cambio de posicion pasa lo contrario es la otra la que no la reconoce ose ano me la deja declarar por que ????

gracias por la ayuda

Código Delphi [-]
unit Unit1;

interface

uses
  SysUtils, Classes, ADODB, syncobjs, Windows , DB, Dialogs;

type
  IConnection = Interface(IInterface)
  function Connection: TADOConnection;
  function GetRefCount: Integer;
  function GetLastAccess: TDateTime;
  property LastAccess: TDateTime read GetLastAccess;
  property RefCount: Integer read GetRefCount;
end;


type
  TDataModule1 = class(TDataModule, IConnection)
  private
    { Private declarations }
    protected
  FRefCount: Integer;
  FLastAccess: TDateTime;
  CriticalSection: TCriticalSection;
  Semaphore: THandle;
  function _AddRef: Integer; stdcall;
  function _Release: Integer; stdcall;
  {IConnection methods}
  function GetLastAccess: TDateTime;
  function GetRefCount: Integer;
  public
  { Public declarations }
    function Connection: TADOConnection;
  end;


  TFixedConnectionPool = class(TObject)
private
  FPool: array of IConnection;
  FPoolSize: Integer;
  FTimeout: LargeInt;
  CleanupThread: TCleanupThread;
  Semaphore: THandle;
  CriticalSection: TCriticalSection;
public
  constructor Create(const PoolSize: Integer = 10;
    const CleanupDelayMinutes: Integer = 5;
    const Timeoutms: LargeInt = 10000); overload;
  destructor Destroy; override;

  function GetConnection: IConnection;
end;

type
  TCleanupThread = class(TThread)
  private
  FCleanupDelay: Integer;
  protected

  CriticalSection: TCriticalSection;
  FixedConnectionPool: TFixedConnectionPool;
  procedure Execute; override;
  constructor Create(CreateSuspended: Boolean;
    const CleanupDelayMinutes: Integer);
end;

var
  DataModule1: TDataModule1;

implementation

{$R *.dfm}


function TDataModule1._AddRef: Integer;
begin

CriticalSection.Enter;
try
  Inc(FRefCount);
  Result := FRefCount;
finally
  CriticalSection.Leave;
end;
end;

function TDataModule1._Release: Integer;
begin

CriticalSection.Enter;
 try
  Dec(FRefCount);
  Result := FRefCount;

  if Result = 0 then
    Destroy
  else
    Self.FLastAccess := Now;
 finally
  CriticalSection.Leave;
  if FRefCount = 1 then
    ReleaseSemaphore(Semaphore, 1, nil);
 end;
end;

constructor TFixedConnectionPool.Create(const PoolSize: Integer = 10;
      const CleanupDelayMinutes: Integer = 5;
      const Timeoutms: LargeInt = 10000);
begin
  FPoolSize := PoolSize;
  FTimeout := Timeoutms;
  Semaphore := CreateSemaphore(nil, PoolSize, PoolSize, '');
  CriticalSection := TCriticalSection.Create;

  SetLength(FPool, PoolSize);

  CleanupThread := TCleanupThread.Create(True, CleanupDelayMinutes);
  with CleanupThread do
  begin
    FreeOnTerminate := True;
    Priority := tpLower;
    FixedConnectionPool := Self;
    Resume;
  end;
end;


constructor TCleanupThread.Create(CreateSuspended: Boolean;
      const CleanupDelayMinutes: Integer);
begin
  // always create suspended
  inherited Create(True); // always create suspended
  FCleanupDelay := CleanupDelayMinutes;
  //Resume if not created suspended
  if not CreateSuspended then
    Resume;
end;

function TFixedConnectionPool.GetConnection: IConnection;
var
  i: Integer;
  DM: TDataModule1;
  WaitResult: Integer;
begin
Result := nil;
WaitResult := WaitForSingleObject(Semaphore, FTimeout);
if WaitResult <> WAIT_OBJECT_0 then
  raise EConnPoolException.Create('Connection pool timeout. '+
    'Cannot obtain a connection');
CriticalSection.Enter;
try
  for i := Low(FPool) to High(FPool) do
    begin

      if FPool[i] = nil then
        begin
          DM := TDataModule1.Create(nil);
          DM.CriticalSection := Self.CriticalSection;
          DM.Semaphore := Self.Semaphore;
          FPool[i] := DM;
          FPool[i].Connection.Connected := True;
          Result := FPool[i];
          Exit;
        end;

      if FPool[i].RefCount = 1 then
        begin
          Result := FPool[i];
          Exit;
        end;
    end;
finally
  CriticalSection.Leave;
end;
end;


destructor TFixedConnectionPool.Destroy;
var
  i: Integer;
begin
  //Free any remaining connections
  CleanupThread.Terminate;
  CriticalSection.Enter;
  try
    for i := Low(FPool) to High(FPool) do
      FPool[i] := nil;
    SetLength(FPool,0);
  finally
    CriticalSection.Leave;
  end;
  CriticalSection.Free;
  //Release the semaphore
  CloseHandle(Semaphore);
  inherited;
end;
end.
Responder Con Cita
  #6  
Antiguo 03-08-2010
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola de nuevo Julyus.

Aca esta el código no me dá errores (de compilación).
Lo reestructuré un poco para mayor legibilidad, no probé la ejecución.
En el código está la línea (1) que soluciona la referencia cruzada entre las clases FixedConnectionPool y TCleanupThread.

Código:
unit Unit2;

interface

uses
  SysUtils, Classes, ADODB, syncobjs, Windows , DB, Dialogs;

type
  IConnection = Interface(IInterface)
    function Connection: TADOConnection;
    function GetRefCount: Integer;
    function GetLastAccess: TDateTime;
    property LastAccess: TDateTime read GetLastAccess;
    property RefCount: Integer read GetRefCount;
  end;

  TFixedConnectionPool = class;  //  (1)   * LINEA ADICIONADA *

  TCleanupThread = class(TThread)
  private
    FCleanupDelay: Integer;
  protected
    CriticalSection: TCriticalSection;
    FixedConnectionPool: TFixedConnectionPool;
    procedure Execute; override;  { FALTABA IMPLEMENTAR }
    constructor Create(CreateSuspended: Boolean;
    const CleanupDelayMinutes: Integer);
  end;

  TFixedConnectionPool = class(TObject)
  private
    FPool: array of IConnection;
    FPoolSize: Integer;
    FTimeout: LargeInt;
    CleanupThread: TCleanupThread;
    Semaphore: THandle;
    CriticalSection: TCriticalSection;
  public
    constructor Create(const PoolSize: Integer = 10;
    const CleanupDelayMinutes: Integer = 5;
    const Timeoutms: LargeInt = 10000); overload;
    destructor Destroy; override;
    function GetConnection: IConnection;
  end;

  TDataModule2 = class(TDataModule, IConnection)
  private
  protected
    FRefCount: Integer;
    FLastAccess: TDateTime;
    CriticalSection: TCriticalSection;
    Semaphore: THandle;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    {IConnection methods}
    function GetLastAccess: TDateTime;   { FALTABA IMPLEMENTAR }
    function GetRefCount: Integer;       { FALTABA IMPLEMENTAR }
  public
    function Connection: TADOConnection; { FALTABA IMPLEMENTAR }
  end;

var
  DataModule2: TDataModule2;

implementation {$R *.dfm}

function TDataModule2.Connection: TADOConnection;
begin
  // IMPLEMENTAR
end;

function TDataModule2.GetLastAccess: TDateTime;
begin
  // IMPLEMENTAR
end;

function TDataModule2.GetRefCount: Integer;
begin
  // IMPLEMENTAR
end;

function TDataModule2._AddRef: Integer;
begin
  CriticalSection.Enter;
  try
   Inc(FRefCount);
   Result := FRefCount;
  finally
   CriticalSection.Leave;
  end;
end;

function TDataModule2._Release: Integer;
begin
CriticalSection.Enter;
 try
  Dec(FRefCount);
  Result := FRefCount;
  if Result = 0 then
    Destroy
  else
    Self.FLastAccess := Now;
 finally
  CriticalSection.Leave;
  if FRefCount = 1 then
    ReleaseSemaphore(Semaphore, 1, nil);
 end;
end;

constructor TFixedConnectionPool.Create(const PoolSize: Integer = 10;
      const CleanupDelayMinutes: Integer = 5;
      const Timeoutms: LargeInt = 10000);
begin
  FPoolSize := PoolSize;
  FTimeout := Timeoutms;
  Semaphore := CreateSemaphore(nil, PoolSize, PoolSize, '');
  CriticalSection := TCriticalSection.Create;
  SetLength(FPool, PoolSize);
  CleanupThread := TCleanupThread.Create(True, CleanupDelayMinutes);
  with CleanupThread do
  begin
    FreeOnTerminate := True;
    Priority := tpLower;
    FixedConnectionPool := Self;
    Resume;
  end;
end;

constructor TCleanupThread.Create(CreateSuspended: Boolean;
      const CleanupDelayMinutes: Integer);
begin
  // always create suspended
  inherited Create(True); // always create suspended
  FCleanupDelay := CleanupDelayMinutes;
  //Resume if not created suspended
  if not CreateSuspended then
    Resume;
end;

function TFixedConnectionPool.GetConnection: IConnection;
var
  i: Integer;
  DM: TDataModule2;
  WaitResult: Integer;
begin
Result := nil;
WaitResult := WaitForSingleObject(Semaphore, FTimeout);
if WaitResult <> WAIT_OBJECT_0 then
  raise Exception.Create('Connection pool timeout. '+  // EConnPoolException: Identificador desconocido
    'Cannot obtain a connection');                     // reemplazo por Exeption
CriticalSection.Enter;
try
  for i := Low(FPool) to High(FPool) do
    begin
      if FPool[i] = nil then
        begin
          DM := TDataModule2.Create(nil);
          DM.CriticalSection := Self.CriticalSection;
          DM.Semaphore := Self.Semaphore;
          FPool[i] := DM;
          FPool[i].Connection.Connected := True;
          Result := FPool[i];
          Exit;
        end;
      if FPool[i].RefCount = 1 then
        begin
          Result := FPool[i];
          Exit;
        end;
    end;
finally
  CriticalSection.Leave;
end;
end;

destructor TFixedConnectionPool.Destroy;
var
  i: Integer;
begin
  //Free any remaining connections
  CleanupThread.Terminate;
  CriticalSection.Enter;
  try
    for i := Low(FPool) to High(FPool) do
      FPool[i] := nil;
    SetLength(FPool,0);
  finally
    CriticalSection.Leave;
  end;
  CriticalSection.Free;
  //Release the semaphore
  CloseHandle(Semaphore);
  inherited;
end;

procedure TCleanupThread.Execute;
begin
  inherited;
  // IMPLEMENTAR
end;

end.
Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 03-08-2010 a las 20:12:45.
Responder Con Cita
  #7  
Antiguo 04-08-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.309
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
ecfisa, si utilizas la etiqueta [ DELPHI ] en lugar de la de [ CODE ] te resalta las palabras reservadas.

Sólo es un comentario. No se si lo desconoces o que te va mejor utilizar la de [ CODE ]
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #8  
Antiguo 04-08-2010
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Cita:
Empezado por Neftali Ver Mensaje
ecfisa, si utilizas la etiqueta [ DELPHI ] en lugar de la de [ CODE ] te resalta las palabras reservadas.

Sólo es un comentario. No se si lo desconoces o que te va mejor utilizar la de [ CODE ]
Hola Neftalí, conozco la etiqueta, pero a veces [delphi] se desconfigura luego de aplicar la vista previa, dejando sólo [+] y todo el texto sin identar.

Quizá sea algún problema de configuración de mi navegador, voy a hacer algo que debería haber hecho antes: Postear el problema en Varios.

Gracias por la observación.


Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #9  
Antiguo 04-08-2010
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.072
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Cierto, no sale bien si se le da al botón de vista previa
Responder Con Cita
  #10  
Antiguo 06-08-2010
Avatar de julyus
julyus julyus is offline
Miembro
 
Registrado: jul 2006
Ubicación: IN TO PLACES COLOMBIA AND EE.UU
Posts: 121
Poder: 18
julyus Va por buen camino
Talking señores muchas gracias

hola amigos gracias por sus respuestas me han servido mucho de ayuda pude cuadrar la unidad y bueno recorde cosas que hace rato no hacia en delphi

mil gracias.

julian abreo
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Algunos videos para pasar el rato Faust Humor 3 24-06-2010 05:09:49
¿como programo el puerto serial con delphi + ensamblador? candia ASM y Microcontroladores 11 23-04-2008 08:07:47
¿Como programo un boton Aceptar? Carmen Conexión con bases de datos 9 03-11-2004 22:11:32
En que programo? Caljim Varios 13 09-08-2004 20:32:05


La franja horaria es GMT +2. Ahora son las 21:20:25.


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
Copyright 1996-2007 Club Delphi