Fórum Ver se o controle possui determinada propriedade #263492
27/12/2004
0
Gandalf.nho
Curtir tópico
+ 0Posts
27/12/2004
Khundalini
[]s
Rubem Rocha
Manaus, AM
Gostei + 0
27/12/2004
Dopi
A finalidade do código é trocar a origem de todos os DataStes de um Form para um outro DataModule (temporário)...
Observe as funçoes: getPropInfo, getordprop
{------------------------------------------------------------------------------
Troca o DataModule de origem de todos os Datasets de "AForm" para o novo
"NewDataModule"
----------------------------------------------------------------------------- }
procedure MudaDataModule( AForm : TForm; NewDataModule : TDataModule ) ;
var
i:longint;
c: TComponent;
propInfo: PPropInfo;
l:longint;
ds: TDataSet;
dsname: string;
Ativo : Boolean ;
begin
for i:=0 to AForm.ComponentCount-1 do
begin
c := AForm.components[i]; // Look for the DataSource property
propInfo := getPropInfo(c.classinfo,´DataSet´);
if assigned(propinfo) then //If found
begin
l := getordprop(c,propInfo); //Gets the property
dsname := TDataSet(l).Name; //Gets the DataSet name
Ativo := TDataSet(l).Active ;
//And gets the instance of the new DataSet
ds := NewDataModule.findcomponent(dsname) as TDataSet ;
if assigned(ds) then
begin
TDataSet(l).Close ;
//Sets the new datasource
setordprop(c,propInfo,longint(ds));
l := getordprop(c,propInfo); //Gets the property
TDataSet(l).Active := Ativo ;
end;
end;
end;
end;
Gostei + 0
27/12/2004
Gandalf.nho
Gostei + 0
02/06/2005
Fabiobb
Use essa função.
// Verificar se existe a propriedade que vc deseja
if IsPublishedProp(Objeto, ´NomePropriedade´) then
// Para setar a propriedade. O valor é variant
SetPropValue(Objeto, ´Propriedade´ , Valor);
// Para recuperar o valor. O último parâmetro diz se vc prefere o conteúdo
em texto ou não. De preferencia chame assim
GetPropValue(Objeto, ´Propriedade´, False);
Espero que tenha sido útil.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)