Hello,
Hope this will help others here...
Finally!! I have managed to solve my problem using following code.
I don't know if this is the best thing or not but it just works as expected..!!
procedure TfrmMain.cmdSaveClick(Sender: TObject);
var
I, ObjID: Integer;
BookType, Orientation, LayWidth, LayHeight: Integer;
PCount, LCount, SCount: Integer;
LayData: String;
SQL: String;
ss: TStringStream;
ms: TStream;
ThumbnailString: String;
begin
//First Validate data
if cboProductType.ItemIndex < 0 then
begin
ShowMessage('Please select Product Type');
cboProductType.SetFocus;
Exit;
end;
if cboOrientation.ItemIndex < 0 then
begin
ShowMessage('Please select Orientation');
cboOrientation.SetFocus;
Exit;
end;
if StrToInt(txtPageWidth.Text) <= 0 then
begin
ShowMessage('Please Enter Page Width');
txtPageWidth.SetFocus;
Exit;
end;
if StrToInt(txtPageHeight.Text) <= 0 then
begin
ShowMessage('Please Enter Page Height');
txtPageHeight.SetFocus;
Exit;
end;
if ievMain.ObjectsCount = 0 then
begin
ShowMessage('There are not Layout Details to save');
Exit;
end;
CalcObjOrientation; //Recalculate Obj Orientation
ievMain.CopyObjectsToBack(true);
if ievMain.IEBitmap.Width > ievMain.IEBitmap.Height then
ievMain.Proc.Resample(50,-1,rfProjectBW,True)
else
ievMain.Proc.Resample(-1,50,rfProjectBW,True);
ss := TStringStream.Create();
ms := TMemoryStream.Create();
//TIdDecoder.DecodeStream();
ievMain.IO.SaveToStreamJpeg(ms);
ms.Seek(0, soFromBeginning);
ThumbnailString := TIdEncoderMIME.EncodeStream(ms);
//ShowMessage(ThumbnailString);
//Save data to DB here
SQL := 'INSERT INTO [layouts] ([lay_book_type], [lay_orientation], [' +
'lay_width], [lay_height], [lay_p_count], [lay_l_count], [lay_s_count], [' +
'lay_data], [lay_preview]) VALUES(';
SQL := SQL + IntToStr(cboProductType.ItemIndex + 1) + ',';
SQL := SQL + IntToStr(cboOrientation.ItemIndex + 1) + ',';
SQL := SQL + txtPageWidth.Text + ',';
SQL := SQL + txtPageHeight.Text + ',';
SQL := SQL + txtPCount.Text + ',';
SQL := SQL + txtLCount.Text + ',';
SQL := SQL + txtSCount.Text + ',';
LayData := '';
for I := 0 to ievMain.ObjectsCount - 1 do
begin
ObjID := ievMain.GetObjFromIndex(I);
LayData := LayData + IntToStr(ievMain.ObjLeft[ObjID]) + ',';
LayData := LayData + IntToStr(ievMain.ObjTop[ObjID]) + ',';
LayData := LayData + IntToStr(ievMain.ObjWidth[ObjID]) + ',';
LayData := LayData + IntToStr(ievMain.ObjHeight[ObjID]) + #13;
end; //for I := 0 to ievMain.ObjectsCount - 1 do
SQL := SQL + Chr(39) + LayData + Chr(39) + ',';
SQL := SQL + Chr(39) + ThumbnailString + Chr(39);
SQL := SQL + ');';
//Execute Query to insert Data in DB
SQLConnection1.ExecuteDirect(SQL);
LoadDataInGrid;
ShowMessage('Layout saved in DB');
end;
TO get the code to work I had to add these units also:
IdCoder, IdCoderMIME
HTH
Yogi Yang