Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: FindStyleResource<T>() syntax error?


This question is answered.


Permlink Replies: 18 - Last Post: Nov 27, 2016 1:58 AM Last Post By: Ahmed Sayed
Ahmed Sayed

Posts: 173
Registered: 8/9/07
FindStyleResource<T>() syntax error?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 22, 2016 5:22 AM
Hi i am having a trouble making this function work.

void __fastcall TFMXNotification::ApplyStyle(void)
{
this->FindStyleResource("Image");
FindStyleResource<TImage*>("Image",FStyleImage);        //errors here
}
//---------------------------------------------------------------------------
 
[bcc32 Error] FMXNotification.cpp(172): E2270 > expected
  Full parser context
    Unit1.cpp(171): parsing: void _fastcall TMyStyledControl::ApplyStyle()
[bcc32 Error] FMXNotification.cpp(172): E2108 Improper use of typedef 'TImage'
  Full parser context
    Unit1.cpp(171): parsing: void _fastcall TMyStyledControl::ApplyStyle()
[bcc32 Error] FMXNotification.cpp(172): E2188 Expression syntax
  Full parser context
    Unit1.cpp(171): parsing: void _fastcall TMyStyledControl::ApplyStyle()


What am i doing wrong? I am using RAD Studio 10 Seattle
--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FindStyleResource<T>() syntax error? [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 22, 2016 11:36 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

Hi i am having a trouble making this function work.

Does TFMXNotification derive from TStyledControl? If not, then you can't
use the templated version of FindStyleResource(), as it only exists in TStyledControl:

void __fastcall TFMXNotification::ApplyStyle(void)
{
    FStyleImage = dynamic_cast<TImage*>(FindStyleResource(_D("Image")));
}


--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2016 8:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
It is inherited from TPanel.

Why? Does it have to be inherited directly from TStyledControl?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FindStyleResource<T>() syntax error? [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2016 11:46 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

Does it have to be inherited directly from TStyledControl?

No.

There are multiple FindStyleResource() methods in various classes in the
hierarchy. You will have to quality one you want to use. This compiles
for me:

void __fastcall TFMXNotification::ApplyStyle(void)
{
    TStyledControl::FindStyleResource<TImage*>("Image", FStyleImage);
}


--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2016 12:26 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I get it now. Thanks very much.

--
The limits of my language mean the limits of my world
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 1:23 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
void __fastcall TFMXNotification::UpdateImage()
{
if (TStyledControl::FindStyleResource<TImage*>("Image", FStyleImage))
	{
	if (!FImage->IsEmpty())
		{
		FStyleImage->Bitmap->Assign(FImage);
		FStyleImage->Visible = true;
		}
	else
		{
		FStyleImage->Visible = false;
		FStyleImage->Bitmap->SetSize(0, 0);
		}
	}
}
//---------------------------------------------------------------------------
void __fastcall TFMXNotification::ApplyStyle(void)
{
inherited::ApplyStyle();
UpdateImage();
}
//---------------------------------------------------------------------------


It compiled fine. but when i tried to run the app.
Ita gave me the following error. Why?

[ilink32 Error] Error: Unresolved external 'bool __fastcall 
Fmx::Controls::TStyledControl::FindStyleResource<Fmx::Objects::
TImage *>(System::UnicodeString, Fmx::Objects::TImage *&)' referenced 
from D:\L-DEVELOPMENT\MAIN LIBRARY\CLOUD BAAS SERVICE\PUSH 
PROJECT\CLIENT\TEST APPS\NOTIFICATIONS LIST\WIN32\DEBUG\FMXNOTIFICATION.OBJ


--
The limits of my language mean the limits of my world
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 2:01 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
El 24/11/2016 a las 10:29, Ahmed Sayed escribió:
It compiled fine. but when i tried to run the app.
Ita gave me the following error. Why?
 

[ilink32 Error] Error: Unresolved external 'bool __fastcall
Fmx::Controls::TStyledControl::FindStyleResource<Fmx::Objects::
TImage *>(System::UnicodeString, Fmx::Objects::TImage *&)' referenced
from D:\L-DEVELOPMENT\MAIN LIBRARY\CLOUD BAAS SERVICE\PUSH
PROJECT\CLIENT\TEST APPS\NOTIFICATIONS LIST\WIN32\DEBUG\FMXNOTIFICATION.OBJ
{code}

This is the problem that occurs when using Delphi generics in C++Builder.

The C++ compiler does not know how to generate the code that implements
generics so you can use only generics that have been explicitly
instantiated in one of the Delphi libraries that are linked in the project.
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 2:13 AM   in response to: Antonio Estevez in response to: Antonio Estevez
And how can i fix this?

--
The limits of my language mean the limits of my world
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 8:10 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
El 24/11/2016 a las 11:13, Ahmed Sayed escribió:
And how can i fix this?

--
The limits of my language mean the limits of my world

How did you declare the FStyleImage variable?
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 8:26 AM   in response to: Antonio Estevez in response to: Antonio Estevez
TImage *FStyleImage;

in private section.

--
The limits of my language mean the limits of my world
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 9:14 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
El 24/11/2016 a las 17:26, Ahmed Sayed escribió:
TImage *FStyleImage;

in private section.

--
The limits of my language mean the limits of my world

Try using the non-generic version of FindStyleResource:

void __fastcall TFMXNotification::ApplyStyle(void)
{
    if (FStyleImage= dynamic_cast<TImage*>(TStyledControl::FindStyleResource(_D("Image"))))
    {
 
    }
}

If you want to use the generic version of FindStyleResource then:
Add a Delphi unit (.pas) to the project.
Save the unit as GenericImpl.pas, by example.
Replace the content of the unit with this:

unit GenericImpl;
 
interface
 
uses FMX.Controls, FMX.Objects;
 
function FindImageStyle(Ctrl: TStyledControl; var Image: TImage): Boolean;
 
implementation
 
function FindImageStyle(Ctrl: TStyledControl; var Image: TImage): Boolean;
begin
    Result:= Ctrl.FindStyleResource<TImage>('Image', Image);
end;
 
end.
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 9:50 AM   in response to: Antonio Estevez in response to: Antonio Estevez
But there are other functions that uses templates and they
work fine with C++ builder without any problems
like: TValue::From<>()

Why this one doesn't work the same way?

--
The limits of my language mean the limits of my world
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 10:57 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
El 24/11/2016 a las 18:50, Ahmed Sayed escribió:
But there are other functions that uses templates and they
work fine with C++ builder without any problems
like: TValue::From<>()

Why this one doesn't work the same way?

--
The limits of my language mean the limits of my world

You can't use Delphi generics from C++ code unless they have been explicitly instantiated with the same type in a Delphi
unit linked to the application.

By example, this links fine:
#include <System.Generics.Collections.hpp>
...
    TList__1<String> *list= new TList__1<String>();
    list->Add(text_str);
...


That is because in some unit from the RTL, VLC or FMX libraries there is a line of code like:
    List:= TList<String>.Create;
    List.Add(TextStr);

But this fails:

#include <System.Generics.Collections.hpp>
...
    TList__1<char> *list= new TList__1<char>();
    list->Add('a');
...


with the errors:
[ilink32 Error] Error: Unresolved external 'System::Generics::Collections::TList__1<char>::'
[ilink32 Error] Error: Unresolved external '__fastcall System::Generics::Collections::TList__1<char>::TList__1<char>()'
[ilink32 Error] Error: Unresolved external '__fastcall System::Generics::Collections::TList__1<char>::Add(const char)'
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 26, 2016 11:23 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

But there are other functions that uses templates and
they work fine with C++ builder without any problems
like: TValue::From<>()
Why this one doesn't work the same way?

Your project was already linking to Delphi code that happen to be using those
particular Generics. That was not the case with FindStyleResource().

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 10:28 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Ok i managed to create my own version in C++


#include <typeinfo>
//---------------------------------------------------------------------------
template<typename T>
bool __fastcall TFMXNotification::TryFindStyleObject(const System::UnicodeString AStyleLookup, T &AResource)
{
TFmxObject *StyleObject;
StyleObject = FindStyleResource(AStyleLookup, false);
 
bool res = (StyleObject != NULL);
 
if (res)
	{
	String TempName = typeid(T).name();              //returns "TImage *"
	TempName.Delete(TempName.Length()-1,2);     // so i had to delete last 2 chars
	res = StyleObject->ClassNameIs(TempName);
 
	if (res)
		AResource = dynamic_cast<T>(StyleObject);
	}
return res;
}
//---------------------------------------------------------------------------

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FindStyleResource<T>() syntax error? [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 26, 2016 11:30 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

Ok i managed to create my own version in C++

Why are you so adament about using a templated version? The non-template
version does not require you to jump through all of these hoops.

#include <typeinfo>

You don't need to use C++ RTTI. You could just use the TFxmObject's own
ClassName() method instead.

For that matter, you don't need to validate the class name manually at all.
dynamic_cast already handles that for you:

template<typename T>
bool __fastcall TFMXNotification::TryFindStyleObject(const System::UnicodeString 
AStyleLookup, T &AResource)
{
    TFmxObject *StyleObject = FindStyleResource(AStyleLookup, false);
    AResource = dynamic_cast<T>(StyleObject);
    return (AResource != NULL);
}


--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error? [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 27, 2016 1:58 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks. I will change the code to what you mentioned here.
--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FindStyleResource<T>() syntax error? [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 26, 2016 11:23 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

And how can i fix this?

How to Handle Delphi Generics in C++
http://docwiki.embarcadero.com/RADStudio/en/How_to_Handle_Delphi_Generics_in_C%2B%2B

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: FindStyleResource<T>() syntax error?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2016 1:50 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Still not working
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02