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

•  Animation Loaders  862

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

•  TDictionary Custom Sort  7 770

•  Fast Watermark Sources  7 443

•  3D Designer  10 673

•  Sik Screen Capture  7 991

•  Patch Maker  8 199

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

•  ListBox Drag & Drop  7 062

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

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

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

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

•  Canvas Drawing  6 677

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

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

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

•  Paint on Shape  3 397

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

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

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

•  Пазл Numbrix  2 800

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

•  Игра HIP  2 519

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

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

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

•  Генератор лабиринта  3 079

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

•  HEX View  2 977

 
скрыть

  Форум  

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

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



Delphi Sources

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



Автор: Serge Gubenko

How can I assign all property values (or if it's not possible only published property values, or some of them) of one class (TComponent) to another instance of the same class? What I want to do is:

MyComponent1. {property1} := MyComponent2. {property1};
{...}
MyComponent2. {propertyN} := MyComponent2. {propertyN};

Is there a better and shorter way to do this? I tried this: MyComponent1 := MyComponent2; But it doesn't work. Why not? Can I point to the second component ?

MyComponent2 and MyComponent1 are pointers to your components, and this kind of assigment leads to MyComponent1 pointing to MyComponent2. But it will not copy its property values.

A better way is to override the assign method of your control, do all property assignment there and call it when you need to copy component attributes. Here's example:

procedure TMyComponent.Assign(Source: TPersistent);
begin
  if Source is TMyComponent then
  begin
    property1 := TMyComponent(Source).property1;
    { ... }
  end
  else
    inherited Assign(Source);
end;

To assign properties you'll need to set this line in the code:

MyComponent1.Assign(MyComponent2); 







Copyright © 2004-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

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