delphi TClientDataSet utf-8 - delphi

everybody!
I try to load data into oIntermediateStream in way like that:
oIntermediateStream : TStringStream;
oClient := TClientDataSet.Create(MainOpScr);
oClient.LoadFromStream(oIntermediateStream);
The problem is I want to see one unicode simbol - 'қ'. But I see it in my MSACCESS database like two symbols - 'Т›' ( in windows-1251 encoding).
I suspected something wrong with my base but if I insert this symbol by clipboard I see correct view of my symbol.?
I am looking now on TXMLTransform, but I am not sure it is rigth way?
Could you advise something, please.

Related

Delphi export to Excel (.xlsx)

When export to xls there is no error when export to xlsx there is error into cell " the number in this cell is formatted as text or preceded by an apostrophe" but there is no apostrophe
why strange behavior happening?
Update:
I using QExport4XLS, QExport4Xlsx, kbmMemTable - datasource.
MemTable.FieldDefs.Add('Price', db.ftFloat, 0, False)
...
MemTable.FieldByName('Price').AsFloat := Value
...
QExport4X*.DataSet := MemTable;
...
QExport4X*.Execute;
I think this is happening because in both cases (xls and xlsx) you are exporting the values as string. The recent version of Excel, show you that it thinks the cell's value could be of another type by showing you the upper left green triangle.
You should check the type while exporting.
Whitout seeing the code is obviously a wild guess.
I using v4.0 so it was component problem as according their bug fix tracker after v4.2 they did fix.

All needed DatabaseFields referenced in FastReport file

Does anybody know how to get all Database-Fields needed by a FastReport report?
Background:
Usually all the data for our reports come directly from delphi and not via a direct database connection.
We have a editor for editing fast report files. We want to show a preview of the reports with data input by the user. Therefore we need to know all the used datasets and the fields of the datsets needed by the report.
Getting the needed datasets of the report can be done with the property:
var
rpReport: TfrxReport
begin
rpReport.DataSets
But how can we get the number and the names of the fields of the datasets?
Every TfrxDataSet descendant has public FieldsCount and GetFieldList functions.
var
fl: TStringList;
fl := TStringList.Create;
rpReport.DataSets[0].DataSet.GetFieldList(fl);
For me it worked by parsing the .fr3 file, that is an xml file.
I use the following regex to get all the fields (including fields just used by expressions):
mDatasetName + '\."(?<fieldname>[^&]+)"'
where mDatasetName is the name of the dataset the fields are needed for. All the names of the datasets I get by the collection:
for I := 0 to rpReport.DataSets.Count - 1 do
mDatasetName := rpReport.Datasets[I].DatasetName;

How do I work with Word Documents without using COM Automation?

I have read multiple posts on the issue, and none seem to come to a decent conclusion to my question. (Perhaps I'm trying to see if anything has popped up lately.)
I have a small charity app that handles pledges. In doing so, it needs to work with and print documents.
Thing is, if Word is open in the background, the app thread will hang and won't respond to the closure of Word, and I have to roll back manually and close word. Sure, that all works fine, but I simply cannot guarantee that the end user will close Word, even if I put the instruction in a user manual.
I'm not too fussed about speed, but I guess that if it can be enhanced, it would be a nice little bonus.
Have any libraries been released for Delphi that will allow me to open, edit, print, and save documents? If not, is there a way to use Word Automation in such a way that it will not conflict with another open handle of Word when opened?
If you use GetActiveOleObject, you will get the running instance of Word.
By using CreateOleObject, you will get a new instance and shouldn't be troubled by other running instances.
In case you use the TWordApplication, wrapper you can set ConnectKind to ckNewInstance to accomplish this. By default, TWordApplication will try to connect with a running instance.
If you want to open edit and print Word documents and you don't mind using RTF format for what you're doing, investigate TRichView.
It will generate rich documents that are in RTF format, which is one of the formats MS word supports. I don't think it directly reads .DOC files but you can convert .DOC and .DOCX into RTF, for most simple files, but certain advanced formatting features would be lost in the conversion.
It has the advantage of working without any need for even any copy of MS Word to be installed on the machine that is going to do the document processing. For production of receipts and other simple documents, this would be the most reliable technique; Don't use Word directly, at all.
procedure PrintViaWord (const filename: string);
const
wdUserTemplatesPath = 2;
var
wrdApp, wrdDoc, wrdSel: variant;
begin
wrdApp:= CreateOleObject ('Word.Application'); // create new instance
sleep (5000); // this fixes a bug in Word 2010 to do with opening templates
wrdDoc:= wrdApp.documents.add (
wrdApp.Options.DefaultFilePath[wdUserTemplatesPath] + '\mytemplate.dot');
wrdDoc.Select;
wrdSel:= wrdApp.selection;
wrdApp.Options.CheckSpellingAsYouType:= 0;
wrdSel.paragraphformat.alignment:= 1;
wrdSel.typetext ('This is a program demonstrating how to open Word in the background'
+ ' and add some text, print it, save it and exit Word');
wrdDoc.SaveAs (filename + '.doc');
wrdApp.ActivePrinter:= 'Konica Minolta 211';
wrdApp.PrintOut;
WrdDoc.SaveAs (filename + '.doc');
wrdApp.quit;
wrdSel:= unassigned;
wrdDoc:= unassigned;
wrdApp:= unassigned
end;

Delphi 7 - Decode Base64 Using TIdDecoderMIME

OK, well this is driving me nuts, lol.
I have a Base64 string and am trying to decode it into a TMemoryStream using TIdDecoderMIME.
My current code is as follows:
Var MStream:TMemoryStream; Decoder:TIdDecoderMIME;
begin
Decoder := TIdDecoderMIME.Create(nil);
MStream := TMemoryStream.Create;
Decoder.DecodeToStream(BSting,MStream);
end;
Where BString = My Base64 string.
Now when the code is ran, I get an error message saying "Uneven size in DecodeToString."
Any ideas?
Any help is greatly appreciated. Thanks.
You're passing to the DecodeToStream function a Base64 string whose length is not a multiple of 4. In other words, the string you're passing is invalid.
Base64 strings are normally padded with trailing "=" signs to make sure their length is a multiple of 4.
Some decoders will try to correct for the missing padding chars while others will not. See the StackOverflow question "Remove trailing “=” when base64 encoding"
The TIdDecoderMime object validates the input by making sure it is a multiple of 4 - which it will be if the padding chars are included in the input.

LoadFromFile with Unicode data

My input file(f) has some Unicode (Swedish) that isn't being read correctly.
Neither of these approaches works, although they give different results:
LoadFromFile(f);
or
LoadFromFile(f,TEncoding.GetEncoding(GetOEMCP));
I'm using Delphi XE
How can I LoadFromFile some Unicode data....also how do I subsequently SaveToFile? Thanks
In order to load a Unicode text file you need to know its encoding. If the file has a Byte Order Mark (BOM), then you can simply call LoadFromFile(FileName) and the RTL will use the BOM to determine the encoding.
If the file does not have a BOM then you need to explicitly specify the encoding, e.g.
LoadFromFile(FileName, TEncoding.UTF8);
LoadFromFile(FileName, TEncoding.Unicode);//UTF-16 LE
LoadFromFile(FileName, TEncoding.BigEndianUnicode);//UTF-16 BE
For some reason, unknown to me, there is no built in support for UTF-32, but if you had such a file then it would be easy enough to add a TEncoding instance to handle that.
I assume that you mean 'UTF-8' when you say 'Unicode'.
If you know that the file is UTF-8, then do
LoadFromFile(f, TEncoding.UTF8).
To save:
SaveToFile(f, TEncoding.UTF8);
(The GetOEMCP WinAPI function is for old 255-character character sets.)

Resources