Recent

Author Topic: Published properties [SKIPPED]  (Read 8473 times)

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Published properties [SKIPPED]
« on: May 18, 2021, 11:56:53 am »
ما هو وضع الـ {$M+} وما هي الـ RTTI وكيف يُمكن الإستفادة من ذلكـ عمليّاً في البرمجة باستخدام الوحدة المذكورة typinfo وقد ذُكر في رابط الموضوع في الوثائق https://www.freepascal.org/docs-html/current/ref/refsu37.html#x90-1120006.7.5 وحدة الـ classes كمثال على ذلكـ وأنّ الـ RTTI تخص القسم Published من الأصناف؟

google translate:

"What is the status of {$ M +} and what is RTTI and how can this be used in practice in programming using the aforementioned unit typinfo. It was mentioned in the topic link in the documents https://www.freepascal.org/docs-html/current/ ref / refsu37.html # x90-1120006.7.5 Class module "Classes unit" as an example - and that RTTI belongs to the published section of classes?"
« Last Edit: May 18, 2021, 02:35:03 pm by pascal111 »
La chose par la chose est rappelé.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Published properties
« Reply #1 on: May 18, 2021, 12:51:15 pm »
RTTI is an advanced topic. If you're new and now learning OOP, you better skip RTTI for now.

https://wiki.lazarus.freepascal.org/Runtime_Type_Information_%28RTTI%29
« Last Edit: May 18, 2021, 01:07:43 pm by Handoko »

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties
« Reply #2 on: May 18, 2021, 02:34:24 pm »
RTTI is an advanced topic. If you're new and now learning OOP, you better skip RTTI for now.

https://wiki.lazarus.freepascal.org/Runtime_Type_Information_%28RTTI%29

حسناً! فلنتخطّاهُ الآن.

google translate:

"Okay! Let us skip it now."
La chose par la chose est rappelé.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Published properties [SKIPPED]
« Reply #3 on: May 18, 2021, 02:55:49 pm »
In case you're still curious, there is a nice article about it:
Run-Time Type Information In Delphi - Can It Do Anything For You?

Though it is for Delphi most concepts apply also to Free Pascal.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties [SKIPPED]
« Reply #4 on: May 18, 2021, 03:46:27 pm »
In case you're still curious, there is a nice article about it:
Run-Time Type Information In Delphi - Can It Do Anything For You?

Though it is for Delphi most concepts apply also to Free Pascal.

ممتاز! سوف أقرأ الرابط الذي زوّدتني به من أجل أخذ فكرة مبدأيّة فلقد أخذتُ بنصيحة @Handoko في تأجيل الإستفسار عن هذا الموضوع لوقت لاحق أنسب حيث عندئذٍ قد أكون قد جمعتُ من المعلومات الأساسيّة ما يكفي مثل الـ OOP.

google translate:

"Excellent! I will read the link you provided to me in order to get an initial idea. I took @Handoko advice to postpone inquiring about this topic for a more appropriate time when I may have gathered enough basic information such as OOP."
La chose par la chose est rappelé.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Published properties [SKIPPED]
« Reply #5 on: May 18, 2021, 04:36:21 pm »
I learned about RTTI some years ago but honestly, I still don't know when should I use it in real projects.

For your information, Lazarus has a set of RTTI controls that are very similar to the common controls (button, edit, checkbox, listbox, memo, etc). You can find it on the RTTI tab in the component tab. Or use the shortcut: Ctrl+Alt+P > type tti in the search box.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Published properties [SKIPPED]
« Reply #6 on: May 18, 2021, 04:46:20 pm »
I learned about RTTI some years ago but honestly, I still don't know when should I use it in real projects.

Yeah, it has relatively little "normal" use. I think I've only ever used it for "debugging" purposes, e.g. when you want to show the friendly name of an enumerated type rather than the value itself and things like that.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Published properties [SKIPPED]
« Reply #7 on: May 18, 2021, 05:04:26 pm »
Yes, that is. Why I haven't think about it! Thank you for telling me it can be used for debugging. I have my own debug module, a kind of ShowMessage function but much powerful. I will add RTTI feature into the module.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Published properties [SKIPPED]
« Reply #8 on: May 18, 2021, 05:06:04 pm »
Code: Pascal  [Select][+][-]
  1.  
I have my own debug module, a kind of ShowMessage function but much powerful. I will add RTTI feature into the module.

Ha! That's exactly what we did :D

Guess you know it already but just in case: don't underestimate the power of variant and const array parameters for such functions ;D
« Last Edit: May 18, 2021, 05:09:31 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties [SKIPPED]
« Reply #9 on: May 18, 2021, 05:10:41 pm »
I learned about RTTI some years ago but honestly, I still don't know when should I use it in real projects.

Yeah, it has relatively little "normal" use. I think I've only ever used it for "debugging" purposes, e.g. when you want to show the friendly name of an enumerated type rather than the value itself and things like that.

في تعلّمنا للبرمجة نقرأ الشروح ونبحث ونُكوّن رؤىً عن الموضوع بحسب فهمنا ثمّ نُحاول أن نصدّر externalize  ذلكـ إلى الجانب العملي للبرمجة والذي هو جانب واقعي نُحاول أن نُثبت ما كوّناه من رؤىً ليكون واقعاً ولكنّنا لا نفطن إلى أنّ ما قد كوّناه من أفكار وتصوّرات عن الموضوع قد يكون خاطئاً فقد يكون الجانب العملي وهو الجانب الواقعي مُختلف تماماً عمّا نظن ،فالبرمجة تعتمد على كيفيّة تنفيذ مفهوم ما بشكل واقعي لنرى شكله الحقيقي وليس مُحاولة تطويع البرمجة نفسها بالتصدير externalize لنُثبت صحّة تصوّراتنا والتي قد تكون خاطئة تماماً ،لذلكـ أرى أنّ الـ RTTI تعتمد على "كيف؟" أكثر من "ما هي؟" أي التطبيق العملي أفضل لفهمها وهذا ما سأحاوله في وقت لاحق إذ يبدو الموضوع مُتقدم عن مستوايَ الآن.

google translate:

"In our learning to program we read explanations, research and form visions about the subject according to our understanding, then we try to externalize that to the practical side of programming, which is a realistic aspect. We try to prove the visions we have formed to be a reality, but we do not realize that the ideas and perceptions we have formed on the topic may be Wrong, it may be the practical side, which is the realistic side, completely different from what we think, because programming depends on how to realistically implement a concept to see its true form and not try to adapt the programming itself by externalize to prove the validity of our perceptions, which may be completely wrong, so I see that the RTTI depends on "how ? " More than "what?" Any practical application is better to understand it, and this is what I will try at a later time, as the topic seems to be ahead "advanced" of my level now."
La chose par la chose est rappelé.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Published properties [SKIPPED]
« Reply #10 on: May 18, 2021, 05:32:07 pm »
... don't underestimate the power of variant and const array parameters for such functions ;D

This is one of the function of my debug module. Nothing amazing but very useful:

Code: Pascal  [Select][+][-]
  1. procedure ShowInfo(const Info: array of const);
  2. var
  3.   S: string;
  4.   i: SmallInt;
  5. begin
  6.   S := '';
  7.   case High(Info) > maxSmallint of
  8.     True:  i := maxSmallint;
  9.     False: i := High(Info);
  10.   end;
  11.   if i < 0 then
  12.     S := 'No argument.';
  13.  
  14.   for i := 0 to High(Info) do
  15.     with Info[i] do
  16.     begin
  17.       if S.Length > 0 then
  18.         S := S + ' ' + LineEnding;
  19.       case VType of
  20.         vtInteger:    S := S + 'Integer: '     + VInteger.ToString;
  21.         vtBoolean:    S := S + 'Boolean: '     +
  22.                              StrIfThenElse(VBoolean, 'True', 'False');
  23.         vtChar:       S := S + 'Char: '        + VChar;
  24.         vtWideChar:   S := S + 'WideChar: '    + VWideChar;
  25.         vtExtended:   S := S + 'Extended: '    + Format('%.2n', [VExtended^]);
  26.         vtString:     S := S + 'ShortString: ' + string(VString^);
  27.         vtPointer:    S := S + 'Pointer: '     + LongInt(VPointer).ToString;
  28.         vtPChar:      S := S + 'PChar: '       + VPChar;
  29.         vtObject:     S := S + 'Object: '      + VObject.ClassName;
  30.         vtClass:      S := S + 'Class: '       + VClass.ClassName;
  31.         vtPWideChar:  S := S + 'PWideChar: '   + VPWideChar;
  32.         vtAnsiString: S := S + 'AnsiString: '  + string(VAnsiString);
  33.         vtCurrency:   S := S + 'Currency: '    + Format('%.2n', [VCurrency^]);
  34.         vtVariant:    S := S + 'Variant: '; //xxx Todo
  35.         vtInterface:  S := S + 'Interface: '; //xxx Todo
  36.         vtWideString: S := S + 'WideString: '; //xxx Todo
  37.         vtInt64:      S := S + 'Int64: '       + VInt64^.ToString;
  38.         vtQWord:      S := S + 'QWord: '       + VQWord^.ToString;
  39.         otherwise     S := S + '<Unknown>';
  40.       end;
  41.     end;
  42.  
  43.   ShowInfo(S, (High(Info)+1).ToString + ' Array of Const' + ArrayMode);
  44.  
  45. end;

I rarely use array of const but I know it can be very useful. For variant, I will avoid as much as I can. I read many negative comments about it.

@pascal111

I see you're very eager to learn Pascal. But learning by reading the documentation sometimes will make your progress slower. The documentation will explain all the features about the topic in detail. But that will make the simple thing become too complex for novice programmer to understand.

The best way to learn OOP - I personally think is - try to design and write a visual component. A while ago a fellow here asked questions about creating a component using the OOP way. Now, he really made some components although still have some minor issues.

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties [SKIPPED]
« Reply #11 on: May 18, 2021, 05:33:06 pm »
I learned about RTTI some years ago but honestly, I still don't know when should I use it in real projects.

For your information, Lazarus has a set of RTTI controls that are very similar to the common controls (button, edit, checkbox, listbox, memo, etc). You can find it on the RTTI tab in the component tab. Or use the shortcut: Ctrl+Alt+P > type tti in the search box.

لديكـ أنت و @lucamar معلومات أكثر منّي وخبرة أفضل في البرمجة ومع ذلكـ إلتبس عليكما الغاية الفعليّة من الـ RTTI فتخيّل ماذا سيحدث معي ؟!  :D

google translate:

"You and @lucamar have more information than me and better programming experience, yet you are both confused about the actual purpose of RTTI so imagine what will happen to me ?! :D"
La chose par la chose est rappelé.

alpine

  • Hero Member
  • *****
  • Posts: 1032
Re: Published properties [SKIPPED]
« Reply #12 on: May 18, 2021, 06:00:50 pm »
*snip*
google translate:

"You and @lucamar have more information than me and better programming experience, yet you are both confused about the actual purpose of RTTI so imagine what will happen to me ?! :D"
The RTTI is very much used for the IDE visual form designer (the object inspector) as well as for component persistence i.e. loading/storing forms, components, etc.
It's just that colleagues are pretty careful not to burden you with so much information in the beginning, I guess :)
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties [SKIPPED]
« Reply #13 on: May 18, 2021, 07:48:54 pm »
... don't underestimate the power of variant and const array parameters for such functions ;D

This is one of the function of my debug module. Nothing amazing but very useful:

Code: Pascal  [Select][+][-]
  1. procedure ShowInfo(const Info: array of const);
  2. var
  3.   S: string;
  4.   i: SmallInt;
  5. begin
  6.   S := '';
  7.   case High(Info) > maxSmallint of
  8.     True:  i := maxSmallint;
  9.     False: i := High(Info);
  10.   end;
  11.   if i < 0 then
  12.     S := 'No argument.';
  13.  
  14.   for i := 0 to High(Info) do
  15.     with Info[i] do
  16.     begin
  17.       if S.Length > 0 then
  18.         S := S + ' ' + LineEnding;
  19.       case VType of
  20.         vtInteger:    S := S + 'Integer: '     + VInteger.ToString;
  21.         vtBoolean:    S := S + 'Boolean: '     +
  22.                              StrIfThenElse(VBoolean, 'True', 'False');
  23.         vtChar:       S := S + 'Char: '        + VChar;
  24.         vtWideChar:   S := S + 'WideChar: '    + VWideChar;
  25.         vtExtended:   S := S + 'Extended: '    + Format('%.2n', [VExtended^]);
  26.         vtString:     S := S + 'ShortString: ' + string(VString^);
  27.         vtPointer:    S := S + 'Pointer: '     + LongInt(VPointer).ToString;
  28.         vtPChar:      S := S + 'PChar: '       + VPChar;
  29.         vtObject:     S := S + 'Object: '      + VObject.ClassName;
  30.         vtClass:      S := S + 'Class: '       + VClass.ClassName;
  31.         vtPWideChar:  S := S + 'PWideChar: '   + VPWideChar;
  32.         vtAnsiString: S := S + 'AnsiString: '  + string(VAnsiString);
  33.         vtCurrency:   S := S + 'Currency: '    + Format('%.2n', [VCurrency^]);
  34.         vtVariant:    S := S + 'Variant: '; //xxx Todo
  35.         vtInterface:  S := S + 'Interface: '; //xxx Todo
  36.         vtWideString: S := S + 'WideString: '; //xxx Todo
  37.         vtInt64:      S := S + 'Int64: '       + VInt64^.ToString;
  38.         vtQWord:      S := S + 'QWord: '       + VQWord^.ToString;
  39.         otherwise     S := S + '<Unknown>';
  40.       end;
  41.     end;
  42.  
  43.   ShowInfo(S, (High(Info)+1).ToString + ' Array of Const' + ArrayMode);
  44.  
  45. end;

I rarely use array of const but I know it can be very useful. For variant, I will avoid as much as I can. I read many negative comments about it.

@pascal111

I see you're very eager to learn Pascal. But learning by reading the documentation sometimes will make your progress slower. The documentation will explain all the features about the topic in detail. But that will make the simple thing become too complex for novice programmer to understand.

The best way to learn OOP - I personally think is - try to design and write a visual component. A while ago a fellow here asked questions about creating a component using the OOP way. Now, he really made some components although still have some minor issues.

هذه ليست دالة ،هذه ناطحة سحاب :o ستحتاج منّي بعض الوقت ﻷفهمها deja vu

بالنّسبة لبرمجة الـ components فأتفق معكـ على ذلكـ ،فأنا بحاجة ﻷن أبدأ موضوع جديد يشرح كيفيّة بناء component من الصفر.

google translate:

"This is not a function, this is a skyscraper :o It will take some time for me to understand deja vu

As for programming the components, I agree with you on that, I need to start a new topic explaining how to build a component from scratch."
La chose par la chose est rappelé.

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Published properties [SKIPPED]
« Reply #14 on: May 18, 2021, 07:59:54 pm »
*snip*
google translate:

"You and @lucamar have more information than me and better programming experience, yet you are both confused about the actual purpose of RTTI so imagine what will happen to me ?! :D"
The RTTI is very much used for the IDE visual form designer (the object inspector) as well as for component persistence i.e. loading/storing forms, components, etc.
It's just that colleagues are pretty careful not to burden you with so much information in the beginning, I guess :)

ليست خطّة سيّئة عدم الخوض في التفاصيل والدقائق في البداية لئلّا يُنشئ ذلكـ ثقلاً على كتفيَّ.

بما أنّ الـ RTTI يُستخدم خاصّةً من أجل البيئة المرئيّة في توفير المعلومات اللازمة للكائنات المُختلفة فهذا يُعدّ إضافةً تُثري البرمجة ولكن يبدو فعلاً كا تفضّلوا من قبل وذكروا أنّها معلومة مُتقدمة أو فلنُركّز الآن على الأسس والركائز التي سنقوّم خبرتنا البرمجيّة عليها ثمّ التفاصيل في وقتٍ لاحق.

google translate:

"Not a bad plan not to go into the details and minutiae at the beginning lest it put a strain on my shoulders.

Since RTTI is used especially for the visual environment in providing the necessary information for the different objects, this is an addition that enriches the programming, but it really appears as you "they" preferred "exerted and said" before and mentioned that it is advanced information, or let us focus now on the foundations and pillars on which we will evaluate "rise" our programming experience and then the details at a later time."
La chose par la chose est rappelé.

 

TinyPortal © 2005-2018