Recent

Author Topic: Creating component from scratch  (Read 10001 times)

engkin

  • Hero Member
  • *****
  • Posts: 2857
Re: Creating component from scratch
« Reply #45 on: May 22, 2021, 11:41:11 pm »
I did exactly the opposite. You see how important TCanvas is. I asked you to check TCanvas documentation, but you said you did not find it. Then I gave you the link to the documentation of LCL and told you TCanvas is part of LCL. Which part did you feel was useless?

I am treating you the way I want to be treated, like an equal.
« Last Edit: May 22, 2021, 11:43:33 pm by engkin »

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #46 on: May 23, 2021, 12:09:05 am »
I did exactly the opposite. You see how important TCanvas is. I asked you to check TCanvas documentation, but you said you did not find it. Then I gave you the link to the documentation of LCL and told you TCanvas is part of LCL. Which part did you feel was useless?

لا أدري ،فقد عُدت مرّةً أخرى إلى الرّابط الذي أعطيتني إياه https://lazarus-ccr.sourceforge.io/docs/lcl/  ﻷبحث عن TCanvas فوجدتني أغضب ،لا أدري ما السبب؟!

google translate:

"I don’t know, I went back to the link you gave me https://lazarus-ccr.sourceforge.io/docs/lcl/ looking for TCanvas and found me getting angry, I don’t know the reason ?!"

I am treating you the way I want to be treated, like an equal.

أُسلوب الـ normality هو الكتابة بطلاقة والفهم والعمل بالمعنى الظاهر من الكلام وأن يكون الكلام يتفق مع ما هو معقول ،لا يكفي الشكل أن يكون طبيعيّاً.

google translate:

"Normality is to write fluently, understand and act with the apparent meaning of speech and that the speech conforms to what is reasonable, the form is not sufficient for it to be natural."

jamie

  • Hero Member
  • *****
  • Posts: 4742
Re: Creating component from scratch
« Reply #47 on: May 23, 2021, 12:19:58 am »
The only true wisdom is knowing you know nothing

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #48 on: May 23, 2021, 12:24:21 am »
Here Is the TCANVAS docs..


https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tcanvas.html


أشكُركـ! أُقدّر لكـ مُساعدتكـ لجعلي أتخطّى هذه المُشكلة.

google translate:

"Thank you! I appreciate your help in getting me over this problem."

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #49 on: May 23, 2021, 12:33:41 am »
عرفتُ الآن كيفيّة الوصول لـ TCanvas من خلال https://lazarus-ccr.sourceforge.io/docs/lcl/ عن طريق الضغط على Index في أعلى الصفحة ثمّ بالبحث عن طريق ctrl+f إذا كان مُستعرضكـ Mozilla Firefox كالذي لديْ.

google translate:

"I now know how to access TCanvas through https://lazarus-ccr.sourceforge.io/docs/lcl/ by clicking Index at the top of the page, then searching via ctrl + f if your browser is Mozilla Firefox is the same as I have."

jamie

  • Hero Member
  • *****
  • Posts: 4742
Re: Creating component from scratch
« Reply #50 on: May 23, 2021, 12:54:52 am »
here Is another DOC you should look at.


https://www.freepascal.org/docs-html/rtl/types/trect.html



https://wiki.lazarus.freepascal.org/Colors


And this is a good branch to keep in your notes.

[url]

[https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/index-4.htmlurl]
The only true wisdom is knowing you know nothing

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #51 on: May 23, 2021, 07:06:23 pm »
It has nothing to do with America. It is all about programming.  :D
 
Quote
You have not yet answered how to align text in the middle "center" of the control.

I thought the question was yours to answer. Ok here is a way to do it:
Code: Pascal  [Select][+][-]
  1.     txt:='Test';
  2.     txtWidth:=Canvas.TextWidth(txt);
  3.     Canvas.TextOut(((Self.Width-txtWidth) div 2),0,txt);

Here is a better way using TextRect instead of TextOut:
Code: Pascal  [Select][+][-]
  1. var
  2. ...
  3.   txtStyle: TTextStyle;
  4. ...
  5.    
  6.   txtStyle := Default(TTextStyle);
  7.   txtStyle.Alignment:=taCenter;
  8.   txtStyle.Layout:=tlCenter;
  9.  
  10.   Canvas.TextRect(R,0,0,txt,txtStyle);


لماذا قُمت باستخدام Default في سطر الكود التالي؟ هل قُمت مثلاً بتصفير أو شحن txtStyle بقيم إبتدائيّة؟ هذا ما فهمته من صفحة الوثائق هنا https://lazarus-ccr.sourceforge.io/docs/rtl/system/default.html

google translate:

"Why did I "you" use Default in the next line of code? For example, did you zero or prime "initial" txtStyle with initial values? This is what I understood from the documentation page here https://lazarus-ccr.sourceforge.io/docs/rtl/system/default.html "
Code: Pascal  [Select][+][-]
  1.   txtStyle := Default(TTextStyle);
  2.  

jamie

  • Hero Member
  • *****
  • Posts: 4742
Re: Creating component from scratch
« Reply #52 on: May 23, 2021, 07:40:24 pm »
That is a shortcut way to use FillByte.

There are other fields in that record that are not used in this case so its easier to zero the complete record of the TextStyle instead of setting all the fields to false or 0 one by one..

The alternate is this

 FillByte(TextStyle, sizeof(TextStyle), 0);

so you see it's shorter to use default, the compiler generates the code needed..

The only true wisdom is knowing you know nothing

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #53 on: May 25, 2021, 04:46:31 pm »
That is a shortcut way to use FillByte.

There are other fields in that record that are not used in this case so its easier to zero the complete record of the TextStyle instead of setting all the fields to false or 0 one by one..

The alternate is this

 FillByte(TextStyle, sizeof(TextStyle), 0);

so you see it's shorter to use default, the compiler generates the code needed..

أُعذروني على تأخّري! فقد كُنتُ أدرسُ مُقدمةً عن قواعد اللغة الإسبانيّة.
كلامكـ @jamie يُوضّح منطقاً ذكيّاً في أدوات Lazarus فيبدو أنّ  default حلٌّ مُوجزٌ للإستخدام المُفصّل بـ FillByte.

google translate:

"Excuse me for being late! I was studying an introduction to Spanish grammar.
Your speech @jamie demonstrates clever logic in Lazarus tools. It appears that default is a short solution for the use detailed by FillByte."

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #54 on: May 25, 2021, 10:39:02 pm »
لقد قُمتُ بتعديل TSimpleControl.Paint في ضوء ما قاله @engkin هكذا:

google translate:

"I modified TSimpleControl.Paint in light of what @engkin said like this:"

Code: Pascal  [Select][+][-]
  1. procedure TSimpleControl.Paint;
  2. var
  3.   R: TRect;
  4.   txtstyle:ttextstyle;
  5.  
  6. begin
  7.  
  8.   txtStyle := Default(TTextStyle);
  9.   txtStyle.Alignment:=taCenter;
  10.   txtStyle.Layout:=tlCenter;
  11.  
  12.   R := Rect(self.left,self.top,Width,Height);
  13.  
  14.   with Canvas do
  15.   begin
  16.  
  17.     Brush.Color := fill_color;
  18.     Brush.Style:=bsSolid;
  19.     FillRect(R); //<--- this line does the work based on the color and style used above
  20.  
  21.  
  22.     TextRect(R,0,0,self.text,txtStyle);
  23.   end;
  24.  
  25. end;            
  26.  

pascal111

  • Sr. Member
  • ****
  • Posts: 284
  • Un trabajo en equipo para programas serias.
Re: Creating component from scratch
« Reply #55 on: May 26, 2021, 04:11:18 pm »
مازلتُ أنتظر الخطوة التالية ولم يُجبني أحد أم هل نكتفي بمجرد هذه المبادئ البسيطة في بناء component؟

google translate:

"I'm still waiting for the next step and no one answered me, or are we content with just these simple principles in building component?"

 

TinyPortal © 2005-2018