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

•  Animation Loaders  655

•  DeLiKaTeS Tetris (Тетрис)  5 665

•  TDictionary Custom Sort  7 626

•  Fast Watermark Sources  7 317

•  3D Designer  10 515

•  Sik Screen Capture  7 835

•  Patch Maker  8 063

•  Айболит (remote control)  8 117

•  ListBox Drag & Drop  6 924

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

•  Графические эффекты  8 184

•  Рисование по маске  7 585

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

•  Canvas Drawing  6 548

•  Рисование Луны  6 478

•  Поворот изображения  5 660

•  Рисование стержней  4 580

•  Paint on Shape  3 283

•  Генератор кроссвордов  4 272

•  Головоломка Paletto  3 406

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

•  Пазл Numbrix  2 745

•  Заборы и коммивояжеры  3 647

•  Игра HIP  2 453

•  Игра Go (Го)  2 435

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

•  Программа укладки плитки  2 286

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

•  Проверка числового ввода  2 508

•  HEX View  2 909

 
скрыть

  Форум  

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-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

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