WordApplication Document add text - delphi

How to paste some text to Word document if i have handle to TWordDocument or _Document?

Paste to the Range object of the document:
Document.Range(EmptyParam, EmptyParam).Paste;
or
Word.ActiveDocument.Range(EmptyParam, EmptyParam).Paste;
You can tell where to paste:
var
R: OleVariant;
..
R := 20;
Document.Range(R, R).Paste;

Related

I can not correctly translate the code from MSDN to Delphi. Section DirectShow Step 6. Add Support for COM

Please help me to translate the code. I don't know C++ well, but I know Delphi syntax well. I want to translate code from MSDN:
Step 6. Add Support for COM.
static WCHAR g_wszName[] = L"My RLE Encoder";
CFactoryTemplate g_Templates[] =
{
{
g_wszName,
&CLSID_RLEFilter,
CRleFilter::CreateInstance,
NULL,
NULL
}
};
and
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
I realized that the first line is a variable. But when translated, it does not work. Error:
This is a string and you defined it as WCHAR.
Next comes the description of the structure, but I do not know such a form.
The last line is also a variable, but it has a / and two values.
In general, I kind of understood the meaning, but do not understand how to write it.
The code roughly translates to Delphi as follows:
const
g_wszName: PWideChar = 'My RLE Encoder';
var
g_Templates: array[0..0] of CFactoryTemplate;
...
g_Templates[0].m_Name := g_wszName;
g_Templates[0].m_ClsID := #CLSID_RLEFilter;
g_Templates[0].m_lpfnNew := #CRleFilter.CreateInstance;
g_Templates[0].m_lpfnInit := nil;
g_Templates[0].m_pAMovieSetup_Filter := nil;
and
var
g_cTemplates: Integer;
...
//g_cTemplates := SizeOf(g_Templates) div SizeOf(g_Templates[0]);
g_cTemplates := Length(g_Templates);

Compare only time portion delphi given time in string

I want to execute code if the now time is over a certain time given in a string:
var
Time,mynowtime:TTime;
begin
mynowtime := ('24:00:00');
Time := Frac(Now);
if Time > mynowtime then
begin
ShowMessage(TimeToStr(Time));
end;
It gives me an error:
'24:00:00' is not a valid date and time.
as Ken White and Remy Lebeau said in Their comments, you can do it like this;
if CompareTime(Time(), EncodeTime(23, 0, 0, 0)) > 0 then
ShowMessage('it''s late');
if the time value is coming from an external source;
var
FmtStngs: TFormatSettings;
Begin
GetLocaleFormatSettings( GetThreadLocale, FmtStngs );
// set format settings, for more info have a look at the link below
if CompareTime(Time(), StrToTime('23:00:00', FmtStngs)) > 0 then
ShowMessage('it''s late');
End;
link

How to transfer a scanned image from WIA ImageFile to TBitmap without saving it to disk?

I'm using this code to acquire the scanned image from WIA:
const
wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}';
wiaFormatPNG = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}';
var
CommonDialog: ICommonDialog;
AImage: IImageFile;
i: Integer;
begin
CommonDialog := CreateOleObject('WIA.CommonDialog') as ICommonDialog;
for i := 1 to Scanner.Properties.Count do
begin
if (Scanner.Properties[i].Name = 'Horizontal Resolution') or
(Scanner.Properties[i].Name = 'Vertical Resolution') then
Scanner.Properties[i].Set_Value(72)
else if Scanner.Properties[i].Name = 'Horizontal Extent' then
Scanner.Properties[i].Set_Value(Round(8.27 * 72))
else if Scanner.Properties[i].Name = 'Vertical Extent' then
Scanner.Properties[i].Set_Value(Round(11.00 * 72));
end;
AImage := IUnknown(CommonDialog.ShowTransfer(Scanner, wiaFormatPNG, True)) as IImageFile;
//Save the image
AImage.SaveFile('D:\1.' + AImage.FileExtension);
imgImage.Picture.LoadFromFile('D:\1.' + AImage.FileExtension);
DeleteFile('D:\1.' + AImage.FileExtension);
end;
Scanner is initialized using this code:
Scanner := DevMgr.DeviceInfos[Integer(cbWIASource.Items.Objects[cbWIASource.ItemIndex])].Connect.Items[1];
And DevMgr and cbWIASource are initialized using this code:
DevMgr := CreateOleObject('WIA.DeviceManager') as IDeviceManager;
for i := 1 to DevMgr.DeviceInfos.Count do
for j := 1 to DevMgr.DeviceInfos[i].Properties.Count do
if DevMgr.DeviceInfos[i].Properties[j].Name = 'Name' then
begin
cbWIASource.Items.AddObject(DevMgr.DeviceInfos[i].Properties[j].Get_Value, TObject(i));
Break;
end;
I was wondering if there is a way to copy the scanned document without first saving it to the disk. I read on MSDN that I can access ARGBData member of ImageFile to access pixel data, but is there a simple way to copy the entire image from FileData to TBitmap? For instance, can I use a TMemoryStream?
Just as an update, I found this example on MSDN. I know nothing about VB, but I guess the Picture object is a wrapper around HBITMAP. So, is it logical to conclude that the ImageFile.Picture property is what I need?
IImageFile has a property FileData with provides access to the binary image data, via IVector.BinaryData

How to create an XML file using TXML Document in Delphi 7

I have used the following code to create the XML Document :
procedure TForm1.btnCreateXMLClick(Sender: TObject);
var
rootName:string;
childName:string;
attrChild:string;
iXml: IDOMDocument;
iRoot, iNode, iNode2, iChild, iAttribute: IDOMNode;
begin
XMLDoc.Active:=false;
XMLDoc.XML.Text:='';
XMLDoc.Active:=true;
XMLDoc.FileName:='C:\Documents and Settings\a\Desktop\New Text Document.xml';
iXml := XmlDoc.DOMDocument;
//iRoot:=iXml.documentElement(iXml.createElement('xml'));
iRoot := iXml.appendChild(iXml.createElement ('xml'));
// node "test"
iNode := iRoot.appendChild (iXml.createElement ('test'));
iNode.appendChild (iXml.createElement ('test2'));
iChild := iNode.appendChild (iXml.createElement ('test3'));
iChild.appendChild (iXml.createTextNode('simple value'));
iNode.insertBefore (iXml.createElement ('test4'), iChild);
// node replication
iNode2 := iNode.cloneNode (True);
iRoot.appendChild (iNode2);
// add an attribute
iAttribute := iXml.createAttribute ('color');
iAttribute.nodeValue := 'red';
iNode2.attributes.setNamedItem (iAttribute);
// show XML in memo
memXMLOutput.Lines.Text:=FormatXMLData(XMLDoc.XML.Text);
end;
I get the output in memXMLOutput but the XML document does not show the output when seen in Notepad ot IE. where is the problem? Thanks in advance
Remove this:
XMLDoc.FileName:='C:\Documents and Settings\a\Desktop\New Text Document.xml';
and add something like this after the code is done creating the XML document:
XMLDoc.SaveToFile('C:\Documents and Settings\a\Desktop\New Text Document.xml');

OpenOffice Calc automation how alter a chart label of a scatter diagram

Hello could you please help me with the following. I have created a scattered chart and draw a chart from data of a column. The used data is not just after the cell which determines the label:
Column O:
Pwm1 <-- This is the cell I want to see as the label
27114 <-- not used data for graph
27055 <-- etc
27092
27070 <-- data for graph starts here
27105
27024
27092 <-- data for graph ends here
I would like the LABEL cell to appear as the Y column label name (Is now 'Column O'), but how?
This as far as I got (code is Delphi but if someone could help me with a basic example that's ok too):
(* Turn the symbol of the data points off *)
oChart.Diagram.SymbolType := _chartChartSymbolTypeNONE;
oDataSeries := oChart.getUsedData;
oDataSequences := oDataSeries.getDataSequences;
ShowMessage(oDataSequences[1].Label.SourceRangeRepresentation);
SourceRangeRepresentation returns the current label, but how to change?
Thanks Ad
This did it:
(*
creat new DataSequence from range representaion
that provides real data and its role in the series
oDataProvider: com.sun.star.chart2.data.XDataProvider
sRangeRepresentation: range address e.g. Sheet1.A1:B2
sRole: role is defined in com.sun.star.chart2.data.DataSequenceRole
*)
Function CreateDataSequence( oDataProvider : Variant; sRangeRepresentation : String; sRole :String ) : Variant;
Var
oDataSequence : Variant;
Begin
(* create .chart2.data.DataSequence from range representation *)
oDataSequence := oDataProvider.createDataSequenceByRangeRepresentation(sRangeRepresentation);
If NOT VarIsEmpty(oDataSequence) Then
oDataSequence.Role := sRole;
Result := oDataSequence;
End;
oNewLabel := CreateDataSequence(oChart.getDataProvider, '$Sheet1.$O$7', 'label');
oDataSequences[1].setLabel(oNewLabel);

Resources