 |
ActiveDelphi .: O site do programador Delphi! :.
|
Exibir mensagem anterior :: Exibir próxima mensagem |
Autor |
Mensagem |
leogazio Colaborador


Registrado: Domingo, 18 de Fevereiro de 2007 Mensagens: 1047 Localização: Alto Paraná - PR
|
Enviada: Ter Nov 01, 2011 3:49 pm Assunto: Separar componente em packages Design/Run Time |
|
|
Olá pessoal, meu problema é o seguinte; Estou escrevendo um componente e nele estou usando as units DesignIntf e DesignEditors, em design time o componente(até onde eu implementei) funciona perfeitamente, o problema é que ao tentar compilar um projeto usando o componente, o projeto não compila e dá erro "File not found: DesignEditors.dcu", aí eu coloco a pasta ToolsAPI no librarypath do Delphi pra tentar resolver só que já aparece outro erro, diz que não existe Proxies.dcu...
Pesquisando na net eu vi que eu preciso separar o componente e as classes dele em dois packages um design time e outro run time e também preciso colocar o procedure Register e as classes herdadas de TStringProperty em units separadas, alguém pode me dar uma ajuda nessa questão? Segue o código do componente;
Código: | unit ERProLocalizaRegistro;
interface
uses
sysutils, classes, controls, dbctrls, variants, messages, windows,
comctrls, stdctrls, forms, DB, ZConnection, dialogs, ZAbstractRODataset, ZAbstractDataset, ZDataset,
ERProLocalizaRegistroModelo, ERPro_Componentes_Funcoes, DesignIntf, DesignEditors;
type
TFieldOrigemProperty = class(TStringProperty)
public
function GetAttributes : TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
TFieldDestinoProperty = class(TStringProperty)
public
function GetAttributes : TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
TERProFieldLink = class(TCollectionItem)
private
FFieldOrigem : String;
FFieldDestino : String;
protected
function GetDisplayName : String; override;
public
procedure Assign(Source: TPersistent); override;
published
property FieldOrigem : String read FFieldOrigem write FFieldOrigem;
property FieldDestino : String read FFieldDestino write FFieldDestino;
end;
TERProFieldLinks = class(TCollection)
private
FOwner : TComponent;
protected
function GetOwner : TPersistent; override;
function GetItem(Index: Integer): TERProFieldLink;
procedure SetItem(Index: Integer; Value: TERProFieldLink);
public
constructor Create(AOwner : TComponent);
property Items[Index: Integer]: TERProFieldLink read GetItem write SetItem;
end;
TERProLocalizaRegistro = class(TComponent)
private
FConexao : TZConnection;
FCommandText : Widestring;
FFormPosition : TPosition;
FFormCaption : TCaption;
FCadastroFilho : TForm;
FDatasetInterno : TZQuery;
FFieldLinks : TERProFieldLinks;
FDestDataset : TDataset;
procedure SetConexao(Value: TZConnection);
procedure SetCommandText(Value: Widestring);
procedure SetFormPosition(Value: TPosition);
procedure SetFormCaption(Value: TCaption);
procedure SetCadastroFilho(Value: TForm);
procedure SetFieldLinks(Value: TERProFieldLinks);
procedure SetDestDataset(Value: TDataset);
public
constructor Create(AOwner: TComponent); override;
{$warnings off}
destructor Destroy;
{$warnings on}
function Execute: Boolean;
published
property Conexao : TZConnection read FConexao write SetConexao;
property CommandText : Widestring read FCommandText write SetCommandText;
property FormPosition : TPosition read FFormPosition write SetFormPosition;
property FormCaption : TCaption read FFormCaption write SetFormCaption;
property CadastroFilho : TForm read FCadastroFilho write SetCadastroFilho;
property FieldLinks : TERProFieldLinks read FFieldLinks write SetFieldLinks;
property DestDataset : TDataset read FDestDataset write SetDestDataset;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterClasses([TERProFieldLink, TERProFieldLinks]);
RegisterComponents('ERPro - Utils', [TERProLocalizaRegistro]);
RegisterPropertyEditor(TypeInfo(String), TERProFieldLink, 'FieldOrigem', TFieldOrigemProperty);
RegisterPropertyEditor(TypeInfo(String), TERProFieldLink, 'FieldDestino', TFieldDestinoProperty);
end;
{ TERProLocalizaRegistro }
constructor TERProLocalizaRegistro.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if not assigned(FrmERProLocalizaRegistroModelo) then
FrmERProLocalizaRegistroModelo := TFrmERProLocalizaRegistroModelo.Create(nil);
FDatasetInterno := TZquery.Create(FrmERProLocalizaRegistroModelo);
FDatasetInterno.Connection := Conexao;
FDatasetInterno.SQL.Text := CommandText;
FFieldLinks := TERProFieldLinks.Create(Self);
end;
destructor TERProLocalizaRegistro.Destroy;
begin
FFieldLinks.Free;
FreeAndNil(FrmERProLocalizaRegistroModelo);
FreeAndNil(FDatasetInterno);
inherited;
end;
function TERProLocalizaRegistro.Execute: Boolean;
var i : integer;
orgm,
dstn : TField;
begin
//ATRIBUI OS VALORES DA PROPRIEDADE FIELDORIGEM PARA FIELDDESTINO,
for i := 0 to Self.FFieldLinks.Count -1 do
begin
orgm := FDatasetInterno.FindField(FFieldLinks.Items[i].FFieldOrigem);
dstn := FDestDataset.FindField(FFieldLinks.Items[i].FFieldDestino);
if (dstn.DataSet.State in [dsInsert, dsEdit]) then
dstn.AsVariant := orgm.AsVariant;
end;
Result := True;
end;
procedure TERProLocalizaRegistro.SetConexao(Value: TZConnection);
begin
FConexao := Value;
if(csDesigning in componentState) and assigned(FDatasetInterno) then
FDatasetInterno.Connection := FConexao;
end;
procedure TERProLocalizaRegistro.SetCommandText(Value: Widestring);
begin
FCommandText := Value;
FDatasetInterno.SQL.Text := FCommandText;
end;
procedure TERProLocalizaRegistro.SetFormPosition(Value: TPosition);
begin
FFormPosition := Value;
end;
procedure TERProLocalizaRegistro.SetFormCaption(Value: TCaption);
begin
FFormCaption := Value;
end;
procedure TERProLocalizaRegistro.SetCadastroFilho(Value: TForm);
begin
FCadastroFilho := Value;
end;
procedure TERProLocalizaRegistro.SetFieldLinks(Value: TERProFieldLinks);
begin
FFieldLinks.Assign(Value);
end;
{ TDatasetInternoFieldProperty }
function TFieldOrigemProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paValueList];
end;
procedure TFieldOrigemProperty.GetValues(Proc: TGetStrProc);
var
Dst : TDataset;
List : TStringList;
i : Integer;
begin
List := TStringList.Create;
try
Dst := TERProLocalizaRegistro(TERProFieldLink(GetComponent(0)).Collection.Owner).FDatasetInterno;
if Assigned(Dst) then
Dst.GetFieldNames(List);
for i := 0 to List.Count-1 do
Proc(List[i]);
finally
List.Free;
end;
end;
procedure TERProLocalizaRegistro.SetDestDataset(Value: TDataset);
begin
FDestDataset := Value;
end;
{ TERProFieldLink }
procedure TERProFieldLink.Assign(Source: TPersistent);
begin
if Source is TERProFieldLink then
begin
FieldOrigem := TERProFieldLink(Source).FieldOrigem;
FieldDestino := TERProFieldLink(Source).FieldDestino;
end
else
inherited; //joga exceção...
end;
function TERProFieldLink.GetDisplayName: String;
begin
Result := Format('Item %d',[Index]);
end;
{ TERProFieldLinks }
constructor TERProFieldLinks.Create(AOwner: TComponent);
begin
inherited Create(TERProFieldLink);
FOwner := AOwner;
end;
function TERProFieldLinks.GetItem(Index: Integer): TERProFieldLink;
begin
Result := TERProFieldLink(inherited Items[Index]);
end;
function TERProFieldLinks.GetOwner: TPersistent;
begin
Result := FOwner;
end;
procedure TERProFieldLinks.SetItem(Index: Integer; Value: TERProFieldLink);
begin
inherited SetItem(Index, Value);
end;
{ TFieldDestinoProperty }
function TFieldDestinoProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paValueList];
end;
procedure TFieldDestinoProperty.GetValues(Proc: TGetStrProc);
var
Dst : TDataset;
List : TStringList;
i : Integer;
begin
List := TStringList.Create;
try
Dst := TERProLocalizaRegistro(TERProFieldLink(GetComponent(0)).Collection.Owner).FDestDataset;
if Assigned(Dst) then
Dst.GetFieldNames(List);
for i := 0 to List.Count-1 do
Proc(List[i]);
finally
List.Free;
end;
end;
end. |
O ponto onde eu tô tendo problemas é ao separar as classes em units, as classes têm várias variáveis privadas as quais eu não consigo acessar em outra unit...
Agradeço a quem puder me dar uma força,
[]'s. |
|
Voltar ao Topo |
|
 |
GustavoToyota Profissional


Registrado: Domingo, 9 de Outubro de 2011 Mensagens: 605 Localização: Sorocaba - SP
|
|
Voltar ao Topo |
|
 |
leogazio Colaborador


Registrado: Domingo, 18 de Fevereiro de 2007 Mensagens: 1047 Localização: Alto Paraná - PR
|
Enviada: Ter Nov 01, 2011 11:06 pm Assunto: |
|
|
Olá Gustavo! Então cara, valeu pela ajuda mas na verdade o meu problema não é esse, passou bem perto mas ainda não é isso. Essa unit "DsgnIntf" de fato era a interface até o Delphi 5, à partir do Delphi 6(meu caso aqui é Delphi 7) ela mudou pra "DesignIntf", eu já fiz tudo isso, coloquei a pasta ToolsAPI no library path, copiei os pas pra pasta lib mas nada resolveu, quero enfatizar que o meu problema ocorre somente quando eu vou tentar compilar um projeto contendo esse componente, o package do componente compila e instala normal de boa, no projeto eu jogo o componente e trabalho com ele em DESIGN TIME normalzinho sem problema, o problema só acontece quando eu tento compilar o projeto...
Quando eu coloco a pasta ToolsAPI no library path, o erro passa a ser outro, já diz que não encontra o "Proxies.dcu", aí garimpando aqui pelo google eu vi um artigo que o cara diz que é só comentar no DesignEditors.pas o "Proxies" no uses e as funções usadas que são dessa unit, o cara mencionou inclusive que a unit Proxies deixou de ser usada à partir do Delphi 6, só que eu tenho componentes que usam essa unit DesignEditors e funcionam aqui normal sem problema.
O meu problema de fato é que eu tô referenciando à essas duas units(DesignIntf, DesignEditors) na classe que vai rodar em RUN TIME e vi que não pode, que o certo a ser feito é; Criar um package separado só pra design onde ficaram localizadas as classes ...Editor. Esse package é aquele que normalmente os desenvolvedores nomeiam com final ...Design, como o zeos por exemplo, tem o package ZComponent e o ZComponentDesign, o package design é aquele que você só compila e o outro você compila e instala... No último post do seguinte tópico o cara explica bem sobre os pacotes do tipo design time e run time, é exatamente isso o que eu preciso;
http://forum.devmedia.com.br/viewtopic.php?p=55897&sid=fd0465d85f9215773ce40131d47ae415
O problema é que eu não estou sendo capaz de separar o componente em units pra poder criar o pacote design time...
Pô, peço desculpas pela confusão de palavras, é que o esse problema aqui tá bem cabeludo mesmo, mas o que realmente vai me resolver aqui vai ser eu conseguir montar o componente em dois packages e as classes do Editor e o registro em units separadas...
Abraços e qualquer ajuda aí vai sempre ser bem vinda, vlw... |
|
Voltar ao Topo |
|
 |
|
|
Enviar Mensagens Novas: Proibido. Responder Tópicos Proibido Editar Mensagens: Proibido. Excluir Mensagens: Proibido. Votar em Enquetes: Proibido.
|
|