Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 773

•  TDictionary Custom Sort  5 887

•  Fast Watermark Sources  5 682

•  3D Designer  8 445

•  Sik Screen Capture  6 020

•  Patch Maker  6 468

•  Айболит (remote control)  6 461

•  ListBox Drag & Drop  5 318

•  Доска для игры Реверси  94 875

•  Графические эффекты  6 666

•  Рисование по маске  5 772

•  Перетаскивание изображений  4 842

•  Canvas Drawing  5 219

•  Рисование Луны  4 944

•  Поворот изображения  4 485

•  Рисование стержней  3 179

•  Paint on Shape  2 425

•  Генератор кроссвордов  3 299

•  Головоломка Paletto  2 607

•  Теорема Монжа об окружностях  3 391

•  Пазл Numbrix  2 245

•  Заборы и коммивояжеры  2 901

•  Игра HIP  1 873

•  Игра Go (Го)  1 785

•  Симулятор лифта  2 121

•  Программа укладки плитки  1 853

•  Генератор лабиринта  2 289

•  Проверка числового ввода  1 978

•  HEX View  2 287

•  Физический маятник  1 954

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Как присвоить все значения полей одного класса, другому такому же классу 2



Автор: Gokhan Ersumer

procedure EqualClassProperties(AClass1, AClass2: TObject);
var
  PropList: PPropList;
  ClassTypeInfo: PTypeInfo;
  ClassTypeData: PTypeData;
  i: integer;
  NumProps: Integer;
  APersistent: TPersistent;
begin
  if AClass1.ClassInfo <> AClass2.ClassInfo then
    exit;
  ClassTypeInfo := AClass1.ClassInfo;
  ClassTypeData := GetTypeData(ClassTypeInfo);
  if ClassTypeData.PropCount <> 0 then
  begin
    GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    try
      GetPropInfos(AClass1.ClassInfo, PropList);
      for i := 0 to ClassTypeData.PropCount - 1 do
        if not (PropList[i]^.PropType^.Kind = tkMethod) then
          {if Class1,2 is TControl/TWinControl on same form, its names must be unique}
          if PropList[i]^.Name <> 'Name' then
            if (PropList[i]^.PropType^.Kind = tkClass) then
            begin
              APersistent := TPersistent(GetObjectProp(AClass1,
                PropList[i]^.Name, TPersistent));
              if APersistent <> nil then
                APersistent.Assign(TPersistent(GetObjectProp(AClass2,
                  PropList[i]^.Name, TPersistent)))
            end
            else
              SetPropValue(AClass1, PropList[i]^.Name, GetPropValue(AClass2,
                PropList[i]^.Name));
    finally
      FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    end;
  end;
end;

Note that this code skips object properties inherited other than TPersistent.








Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте