What is wrong with this code?

The class below which is inherited from TRectangle, when instantiated and added to a form, is supposed to draw a rectangle with a label centered inside it. I do not have much experience with writing components, etc. but I have based this on one of the response to a questions that was asked in this forum.

It does that properly, i.e. draws rectangle with a label inside it. But also what happens is that when the focus goes away from the rectangle, such as by clicking on some other control on the form, the effects applied to the label inside is misbehaving. This happens on the device as well the simulator. I think either I am doing it wrong, or I am missing some important step. I will appreciate any suggestions or advice on this.

Just add this code to a Firemonkey mobile app and click on the button multiple times.

{code}
unit Letter;

interface

uses
  FMX.Objects, System.Classes, FMX.Effects, FMX.StdCtrls, FMX.Types,
  System.UITypes, System.UIConsts;

type
  TLetter = class(TRectangle)
  private
    FInnerGlowEffect : TInnerGlowEffect;
    FGlowEffect : TGlowEffect;
    FLabel : TLabel;
    FFont : TFont;
  protected

  public
    constructor Create(Owner : TComponent); override;
    procedure Paint; override;
  end;

implementation

{ TLetter }

constructor TLetter.Create(Owner: TComponent);
begin
  inherited Create(Owner);

  FInnerGlowEffect := TInnerGlowEffect.Create(self);
  FInnerGlowEffect.GlowColor := claBlack;
  FInnerGlowEffect.Parent := self;

  FFont := TFont.Create;
  FFont.Family := 'Arial';
  FFont.Size := 30;
  FFont.Style := [TFontStyle.fsBold];

  FLabel := TLabel.Create(self);
  FLabel.StyledSettings := FLabel.StyledSettings -
                [TStyledSetting.ssSize, TStyledSetting.ssFamily,
                  TStyledSetting.ssFontColor, TStyledSetting.ssStyle];
  FLabel.AutoSize := True;
  FLabel.TextAlign := TTextAlign.taCenter;
  FLabel.Font := FFont;
  FLabel.FontColor := claBlack;
  FLabel.Text := 'X';
  FLabel.Align := TAlignLayout.alCenter;
  FLabel.Parent := self;

  FGlowEffect := TGlowEffect.Create(FLabel);
  FGlowEffect.GlowColor := claBlack;
  FGlowEffect.Opacity := 0.5;
  FGloweffect.Softness := 0.4;
  FGlowEffect.Parent := FLabel;

  Width := 50;
  Height := 50;

  FLabel.UpdateEffects;
end;

procedure TLetter.Paint;
begin
  inherited;
end;
end.
{code}

Here's how it is called from a form.
{code}
procedure TForm2.Button2Click(Sender: TObject);
var
  Ltr : TLetter;
begin
  Ltr := TLetter.Create(self);
  Ltr.Position.X := 50;
  Ltr.Position.Y := 50;
  Ltr.Parent := self;
end;
{code}
0
Karu
7/6/2013 5:10:09 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

2 Replies
1136 Views

Similar Articles

[PageSpeed] 48

> {quote:title=Karu Kaarigar wrote:}{quote}
> The class below which is inherited from TRectangle, when instantiated and added to a form, is supposed to draw a rectangle with a label centered inside it. I do not have much experience with writing components, etc. but I have based this on one of the response to a questions that was asked in this forum.
> 
> It does that properly, i.e. draws rectangle with a label inside it. But also what happens is that when the focus goes away from the rectangle, such as by clicking on some other control on the form, the effects applied to the label inside is misbehaving. This happens on the device as well the simulator. I think either I am doing it wrong, or I am missing some important step. I will appreciate any suggestions or advice on this.
> 
> Just add this code to a Firemonkey mobile app and click on the button multiple times.

I tried a simpler version of the same code to accomplish the same. But even here too there is sam behavior as before - can some one try this out? Just create a simple iOS mobils app and add a button ans following code for button click handler:

{code}
procedure TForm2.AddLetterBox(Top : Single; Left : Single);
var
  Rect : TRectangle;
  Lbl : TLabel;
  InnerGlowEffect : TInnerGlowEffect;
  GlowEffect : TGlowEffect;
  Font : TFont;
begin
  Rect := TRectangle.Create(self);
  Rect.Width := 50;
  Rect.Height := 50;
  Rect.Position.X := Left;
  Rect.Position.Y := Top;
  Rect.Parent := self;

  InnerGlowEffect := TInnerGlowEffect.Create(self);
  InnerGlowEffect.GlowColor := claBlack;
  InnerGlowEffect.Parent := Rect;

  Font := TFont.Create;
  Font.Family := 'Arial';
  Font.Size := 30;
  Font.Style := [TFontStyle.fsBold];

  Lbl := TLabel.Create(self);
  Lbl.StyledSettings := Lbl.StyledSettings -
                [TStyledSetting.ssSize, TStyledSetting.ssFamily,
                  TStyledSetting.ssFontColor, TStyledSetting.ssStyle];
  Lbl.AutoSize := True;
  Lbl.TextAlign := TTextAlign.taCenter;
  Lbl.Font := Font;
  Lbl.FontColor := claBlack;
  Lbl.Text := 'X';
  Lbl.Align := TAlignLayout.alCenter;
  Lbl.Parent := Rect;

  GlowEffect := TGlowEffect.Create(self);
  GlowEffect.GlowColor := claBlack;
  GlowEffect.Opacity := 0.5;
  Gloweffect.Softness := 0.4;
  GlowEffect.Parent := Lbl;
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
  AddLetterBox(50, 50);
end;
{code}
0
Karu
7/7/2013 12:22:53 AM
> {quote:title=Karu Kaarigar wrote:}{quote}
> I tried a simpler version of the same code to accomplish the same. But even here too there is sam behavior as before - can some one try this out? Just create a simple iOS mobils app and add a button
 > ans following code for button click handler:
It seems this is a bug with TGLowEffect as it is applied to TLabel. I will still appreciate if someone can confirm it. Thanks.
0
Karu
7/7/2013 3:48:15 AM
Reply:

Similar Artilces:

Transferring Delphi 5 BDE code to Delphi 2006 Nexus Embedded server code
In an application where I have used BDE in Delphi 5 I would like to transfer the whole project to Nexus Embedded server that in general implies mostly exchanging tTable with tnxTable etc. But, in a procedure I regenerate indexes using dbiRegenIndexes(basehandler). This function seems not to be supported anymore, so I just wonder if such a call is needed at all in Nexus Embedded Server, and if needed, what is now the correct syntax ?? I don't know the answer to your question but if you can't find answers here you may like to know that nexus db have there own free newsgr...

WRONG WRONG WRONG
Name: ROZ mandelcorn Email: thunderstaratearthlinkdotnet Product: Firefox Summary: WRONG WRONG WRONG Comments: as a long-time user, first of netscape and, mozilla firefox, i must say i DO NOT LIKE THE PLACEMENT of TABS in version 4. nor do i like the whole rearrangement of the upper/navigation portion of firefox. I NEED/WANT MY TABS DIRECTLY ABOVE MY WINDOWS AS IT IS NOW....NOT ON TOP OF THE BROWSER. I WANT MY FILE-EDIT-ETC-MENU on TOP. ETC. AT LEAST GIVE US THE CHOICE AS TO WHICH FORMAT WE WANT....CAN YOU SAY CUSTOMIZATION! I WILL NOT USE 4 IF THIS IS THE WAY IT IS. [just ...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Making Wrong Code Type Wrong
--4OpS+d6oOtUQaRm1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable JoelOnSoftware wrote an article I recently saw linked on perlmonks: http://www.joelonsoftware.com/articles/Wrong.html The article discusses writing robust software, specifically by dealing with data separation. In my interpretation the article introduces a type system. This type system helps write robust software, but has some limitations: * Type information is checked by the programmer * Full annotations must be supplied by the programme...

converting delphi code to delphi .NET
Hi,I'm looking at converting quite a bit of old delphi code to delphi .NET .  I'm wondering can it be converted to VB.NET for certain ?  Or perhaps there are some unsupported functions etc in delphi and I should keep the code delphi ?  There are about 10,000 lines of code.   Anyone brave enough to take an estimate on how long it would take to convert 10,000 lines ?is going from delphi to delphi.NET smooth ?   Would going to another language cause complications ?Thanks! mike123   Mike123,   Sorry I can not help, however, I have the s...

C++ code to Delphi 7 code
I need the following C++ code convert to Delphi 7 struct FixError { AnsiString section; //Registry section name AnsiString value_name; //Value Name AnsiString value; //Value Data error_reason er; //Error Reason AnsiString file_name; //IF the error reason is system_file (only config_files section) type_of_fix tof; //What shall we do with this error (Delete it OR Leave it) AnsiString uninst_reg_path; //Not used ??? /* Here we are telling the compiler that if someone is comparing the contents of this structure using the != operator then it should com...

delphi 2006 code in delphi 2010
hello, is there any option to make delphi 2006 code work in delphi 2010? something like in java IDEs where you can define the code level you like to use? the problem is, that i made a project with 2006 and sent it to my customer. they got 2010 and it compiles fine, but it just doesn't work. it deals with en-/decryption of text, we assumed, that it has something to do with ansi vs. unicode strings... but we cant find the exact position where the error occurs. i am a bit dissapointed, because everywhere i read that the new IDE will always be downwards compatible and so on.. but in ...

Code Insight / Code Copletion in Delphi XE2
Hi, I've just changed to Delphi XE2 Professional. I have been working with D7 for years, did a few Projects with D2007 and Lazarus. All of these use some form of "Code Insight" - showing a drop down with available properites or methods for the current object. When I start to type the propertie's name the list opens. In D7, 2007, Lazarus the first Item in the list is automatically selected, so if I just type a separator (space, return, :, ; etc), the selected symbol is inserted. In XE2 I have to actively select a symbol from the list and confirm it wi...

Code Porting
Hi people, Basically, I am moving an app from Delphi 5 to Delphi 2009 which is all great (yeah right!) and I am having a couple of issues with some thirdparty components that we have the source code for. Being that I wanted to make the task as easy as possible, I was able to download the component in Delphi 2007 format. I have now managed to port that to 2009 so it compiles only with warnings and no errors. So all is good at this moment. Now I am trying to install the component into the IDE by using the install menu option from the project manager. This is where I run into errors. ...

Convert C code to Delphi code? Pls!
I am writing Excel Add-In XLL in Delphi. I read documents for making XLL in VC++ from Microsoft [http://msdn.microsoft.com/en-us/library/aa730920.aspx] I am converting C code to Delphi code to make XLL in Delphi IDE. I converted it but may be errors? Somebody help me to correct it please! [CODE] //C++ typedef INT32 BOOL; /* Boolean */ typedef WCHAR XCHAR; /* Wide Character */ typedef INT32 RW; /* XL 12 Row */ typedef INT32 COL; /* XL 12 Column */ [B]//DELPHI[/B] type INT32 = Integer; BOOL= INT32; //* Boolean */ XCHAR= WideChar ; //* Wid...

Java opens the word code into Delphi code
//Android gets a used to open the Excel files in intent public static Intent getExcelFileIntent( String param ){ Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/vnd.ms-excel"); return intent; } //Android gets a used to open the Word files in intent ...

Is it worth to move my code from Delphi 2009 to Delphi 2010?
Hi guys, we are working on Delphi 2009 till this day because we do not have the time to upgrade our code to the newest version. There is always something more important (features, bugs...) and our code has 2+ million lines. I thought that instead of moving from D2009 to XE7 I could atleast move code to D2010 because it is more or less backward compatible and it shouldn't take me that much of a work. I wanted to ask you about your opinion. Is it a good version to move to? Regards. Dimitrij wrote: > I thought that instead of moving from D2009 to XE7 I could atleast > move ...

Delphi 7.0 code convert to delphi XE ...
Hello All, I create an application using Web Server Application then CGI stand alone... In WebModule I add ModuleController component and IWPageProcedure... Below is my code in Delphi 7.0, this is how to call another units in webmodule... .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1.proLogInGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmLogIn.Create(AWebA...

[Delphi 2007] Fake code-errors in Code-Editor
Hi, I'm facing following problem: sometimes (w/o visible reason) IDE marks portions of my unit's code as erroneous (mostly "undeclared identifier" in "structure" window) despite code is OK. It's enough to delete one empty line from the code and everything backs to normal. Of course despite of error messages code compiles sucessfully. Anyone faced such behaviour ? My version is 11.0.2902.10471 wirh dec 2007 update installed ,OS is XP SP3 Thanks in advance Mati. Mateusz Kaleta wrote : > I'm facing following problem: sometimes (w/o visi...

[D2010] Can I use Assembly code in my Delphi code?
Hello all, I am new to Delphi, and I am just installing the trial version, but I have some question. Can I use assembly code without restrictions in my Object Pascal/Delphi code? Many thanks! Greets DelphiLynx I'm not quite certain what you mean by "without restriction", but yes you can use assembly code. I don't believe how to do so is documented though. However, you can look at VCL for some examples. Search in the VCL for ASM and you should find some. A quick google search also found this: http://delphi.about.com/library/bluc/text/uc052501a.htm none no...

Web resources about - What is wrong with this code? - embarcadero.delphi.firemonkey

Wrong - Wikipedia, the free encyclopedia
while civil law countries tend to have some additional categories, such as contraventions . Moral wrong is an underlying concept for legal wrong, ...

NASCAR Directs Facebook Users To Wrong TV Network For Pure Michigan 400
Facebook pages are a useful tool for brands to share information, but they may want to ensure that the information being shared is correct, which ...

Ken Ham - Well, our new “Thank God You're Wrong” billboard... - Facebook
Well, our new “Thank God You're Wrong” billboard campaign began with a big bang (☺ ) yesterday—which we praise the Lord for. As expected, many ...

Facebook says bug caused wrong contact syncing on some users’ phones
A contact synchronization bug, combined with Facebook’s latest changes to users’ email visibility settings , led some mobile phones to update ...

What Went Wrong (@AmericaWWW) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Scripting News: Silicon Valley is wrong about college.
Lately I've been thinking a lot about startup culture, and am reminded of its nobility having started three companies in my career, and learned ...

Scripting News: Why Charles Pierce is wrong about Ezra Klein being wrong.
... Pierce's attitude many times, from all kinds of ink-stained pros, some very accomplished. The arrogance is impressive, but they're still wrong. ...

Scripting News: I had to get a NYT Digital Subscription to figure out what's wrong.
Yesterday I posted a tweet with some feedback for the NY Times marketers. Getting a NYT Digital Subscription should open up something new and ...

Scripting News: Privacy is the sometimes wrong word.
You can talk about the security of your personal information in a different ways, each of which suggests a different set of issues. If I call ...

Don’t Take the Wrong Paths to Power
... it, and hoard it. If you have to bruise egos along the way, so what? No one will care or even remember how you got to the Don’t Take the Wrong ...

Resources last updated: 12/20/2015 7:27:35 PM