Ahmed Sayed

Member since: Wednesday, 04 March 2015
Last login: 2 years ago
Profile viewed: 1,292 views

Your Rank: 86
Points: 8

Ahmed Sayed is friends with Jim McKeeth

Ahmed Sayed posted a comment on More Amazing MVPs 3 years ago

Thanks to you all, Thank you Jim McKeeth for the great opportunity I hope I can meet all your expectations

In step 12. This project is part of a package. When we build the EMS Package we get Warnings that we have dependencies, like this. This is fine and expected. So we click OK to add these needed dependencies to the project. If you re-build you shou

Ahmed Sayed created a new topic ' C++ Assignment Operator as the Delphi Implicit Ope' in the forum. 5 years ago

In C++ it is possible to use the operator= for assignment to the result type, the same as the implicit operator is used in Delphi.
For instance, given the variable myVar with TValue type, in Delphi, it is possible to assign different types to this variable as follows:

a := 'assigning a string';
a := 123;
a := 3.14;

Previously in C++, without the assignment operator, you had to write it like this:
a = TValue::_op_Implicit(UnicodeString(L"assigning a string"));
a = TValue::_op_Implicit(123);
a = TValue::_op_Implicit(3.14L);

Now in C++, with the assignment operator, you can write it as:
a = UnicodeString(L"assigning a string");
a = 123;
a = 3.14L;

But this does not work for FMX controls for StyleData[""] or Data as follows and i don't know why:
TValue a;
a = UnicodeString(L"image.jpg");            //Works fine
a = 123;
a = 3.14L;

Panel1->StylesData["Data"] = UnicodeString(L"image.jpg");    //Error here

Image1->Data = String(L"image.jpg");           //Error here

[bcc32 Error] Unit1.cpp(25): E2034 Cannot convert 'UnicodeString' to 'TValue'

Isn't this feature should has been working for any property with type TValue? How come this is not working?
Read More...

Ahmed Sayed created a new topic ' TValue as an event handler inside a dll' in the forum. 5 years ago

Hello everyone,

I am facing a big problem passing a TValue to dll function that after that iside the dll it is converted to an event handler.
Well, Here is what i am doing:

//Host Application
void __fastcall Login(UnicodeString User, UnicodeString Pass, bool &Accept)
{
//authenticate here
}
//Then i pass this event as a TValue to dll like this:
ExecuteForm(Handle, Params, TValue::From<TUserLogin>(Login));

//Dll 

void DLLEXPORT ShowDBForm(HWND CallingApp, TValue Value)
{
if (!ThisApp)
	{
	ThisApp = Application;
	Application->Handle = CallingApp;
	}

if (Value.IsEmpty())
    return;

if (Value.IsType<TUserLogin>())
      {
      TDllForm * Form - new TDllForm(Application);
      Form->OnLogin = Value.AsType<TUserLogin>();     // raise error on type cast
       }

I need to TValue so i can use this "ShowDBForm" with any form create and the TValue might hold something different every time a new dll is created. ( a multi purpose parameter ).

If any of you could help me that will be really great, and i appreciate it
Thanks in advance.
--
The limits of my language mean the limits of my world
Read More...

Ahmed Sayed created a new topic ' TFrame inside a dll' in the forum. 5 years ago

Hello everyone,

I am trying to create custom TFrame decedents inside a dll but I am facing a major problem with TFont. I get the famous error “Cannot assign TFont to TFont”.

The dll is built without linking to run-time packages so as the calling app, I don’t want to use packages (BPL) instead of dll and I don’t want to link with run-time packages. Also note that I am using DevExpress controls and styles on both (Frames and App).

I have no idea how to fix this is? Is this a limitation in Delphi or just C++ builder?

Please someone help me in this if there is some kind of workaround or anything else.

Thanks in advance.
Read More...

Ahmed Sayed created a new topic ' TFDMemTable REST Client ApplyUpdates' in the forum. 5 years ago

Hello everyone,

I am trying to create a very dynamic way in handling client / server REST apps with FireDAC to get data from server and apply data back to server using REST Client API.

I managed to get data by using the following code:
{code}
//REST Datasnap Server side
void TServerMethods1::QueryToStream(UnicodeString SQL)
{
FDQuery1->Close();
FDQuery1->SQL->Text = SQL.Trim();
FDQuery1->Open();
TStringStream* aStream = new TStringStream();
FDQuery1->SaveToStream(aStream, sfJSON);
aStream->Position = 0;
GetInvocationMetadata()->ResponseCode = 200;
GetInvocationMetadata()->ResponseContent = aStream->DataString;
aStream->DisposeOf();
}
//


//My FireDAC functions
//
UnicodeString DataSetToStream(TFDAdaptedDataSet *DataSet)
{
UnicodeString res;
TStringStream* aStream = new TStringStream();
DataSet->SaveToStream(aStream, TFDStorageFormat::sfJSON);
aStream->Position = 0;
res = aStream->DataString;
aStream->DisposeOf();
return res;
}
//
UnicodeString QueryToStream(TFDConnection *Con, UnicodeString SQL)
{
UnicodeString res;
TFDQuery *Query = NewQuery( Con, SQL);
res = DataSetToStream(Query);
Query->DisposeOf();
return res;
}
//
void StreamToDataSet(TFDAdaptedDataSet *DataSet, TByteDynArray ABytes)
{
TStream *str = new TMemoryStream();
str->Write(ABytes, ABytes.Length);
str->Position = 0;
DataSet->LoadFromStream(str, sfJSON);
str->DisposeOf();
ABytes.Length = 0;
}
//
//My REST Client Functions
//
TRESTResponse *RESTRequest(TRESTClient *RESTClient, UnicodeString Resource)
{
TRESTRequest *RESTRequest = new TRESTRequest(NULL);
TRESTResponse *RESTResponse = new TRESTResponse(NULL);
RESTRequest->Client = RESTClient;
RESTRequest->Response = RESTResponse;
RESTRequest->Resource = Resource;
RESTRequest->Execute();
RESTRequest->DisposeOf();
return RESTResponse;
}
//
TRESTResponse *RESTRequest(UnicodeString BaseURL, UnicodeString Resource)
{
TRESTClient *RESTClient = new TRESTClient(NULL);
RESTClient->BaseURL = BaseURL;
TRESTResponse *RESTResponse = RESTRequest(RESTClient, Resource);
RESTClient->DisposeOf();
return RESTResponse;
}
//
TByteDynArray RESTRequestBytes(UnicodeString BaseURL, UnicodeString Resource)
{
TByteDynArray ResponseContent;

TRESTResponse *RESTResponse = RESTRequest(BaseURL, Resource);
ResponseContent = RESTResponse->RawBytes;
RESTResponse->DisposeOf();
return ResponseContent;
}
//
//Client side Button click
void __fastcall TForm1::Button1Click(TObject *Sender)
{
StreamToDataSet(FDMemTable1,RESTRequestBytes("http://community.embarcadero.com:8080/datasnap/rest/TServerMethods1/QueryToStream/select * from countries”) );
}
//
{code}

The data is downloaded from the server just fine, now I want to ApplyUpdates back to the server using TRESTRequest component without the need to use EMS at all.

Off course on the server will be a method called, for example:
{code}
ApplyUpdates(UnicodeString SQL, TStream *or UnicodeString DeltaStream);
{code}

Now what is the right way to it? Any help o ideas will be very appreciated.

I have seen a code in file REST.Backend.EMSFireDAC.pas and i want to create something similar in applying updates in datasnap but using the REST Client API.
{code}
procedure TCustomEMSFireDACClient.PostUpdates;
var
LStream: TStream;
I: Integer;
LDataSet: TDataSet;
begin
CheckSchemaAdapter;
CheckProvider;
UpdateEndpoints;

for I := 0 to FSchemaAdapter.Count - 1 do
begin
LDataSet := FSchemaAdapter.DataSets;
if LDataSet <> nil then
if LDataSet.State in dsEditModes then
LDataSet.Post;
end;

LStream := TMemoryStream.Create;
try
FSchemaAdapter.ResourceOptions.StoreItems := [siDelta, siMeta];
FSchemaAdapter.SaveToStream(LStream, TFDStorageFormat.sfJSON);

LStream.Position := 0;
FApplyEndpoint.Params.Clear;
FApplyEndpoint.AddBody(LStream, TRESTContentType.ctAPPLICATION_JSON);
FApplyEndpoint.Execute;

// FSchemaAdapter.Reconcile;
finally
LStream.Free;
end;

end;
{code}

--
Ahmed

Read More...