I form the MS Word document, and insert sound files from the database.

var LClassType, LFileName, LLinkToFile, LDisplaySaIcon, LIconFileName, LIconIndex, LIconLabel, LRange: Olevariant; begin … LClassType := 'Package'; LFileName := PrPathForVoice+ibqEmpty.FieldByName('EW1').AsString+'.mp3'; LLinkToFile := false; LDisplaySaIcon := false; WordApplication1.Selection.InlineShapes.AddOLEObject(LClassType, LFileName, LLinkToFile, LDisplaySaIcon, EmptyParam, EmptyParam, EmptyParam, EmptyParam); … end; 

In Word, they look like icons (labels) of a certain size.
I want to reduce the size of these icons .
I would look at it in the macro itself, but the thing is that during the recording of the macro, it is impossible to resize. It can be changed only after the end of the macro recording.
Although the last parameter of the "AddOLEObject" function is "LRange" - but in my opinion, it’s not quite a bit, considering .
The macro in MSWord looks like this:

 Set y = Selection.InlineShapes.AddOLEObject(ClassType:="Package", FileName:= _ "D:\Prog\Eng_gdb\Documents\Voice\accept.mp3", LinkToFile:=False, _ DisplayAsIcon:=False) y.Height = 20 y.Width = 20 

But if translated into Delphi, then:

 WordApplication1.Selection.InlineShapes.AddOLEObject(LClassType, LFileName, LLinkToFile, LDisplaySaIcon, EmptyParam, EmptyParam, EmptyParam, EmptyParam).Height := 20; WordApplication1.Selection.InlineShapes.AddOLEObject(LClassType, LFileName, LLinkToFile, LDisplaySaIcon, EmptyParam, EmptyParam, EmptyParam, EmptyParam).Width := 20; 

But this adds two objects with different heights and widths.
Do I somehow need to assign dimensions to an object before insertion?

  • 2
    The full answer does not pull, but: not quite correct translation in Delphi. It should be like this: obj: = WordApp1.Selection.InlineShapes.AddOleObject (); obj.Height: = 20; obj.Width: = 20; - kami

1 answer 1

Something like this:

 var MyOLEObject: T{что_там_возвращает_AddOLEObject}; ... MyOLEObject := WordApplication1.Selection.InlineShapes.AddOLEObject(LClassType, LFileName, LLinkToFile, LDisplaySaIcon, EmptyParam, EmptyParam, EmptyParam, EmptyParam); MyOLEObject.Height := 20; MyOLEObject.Width := 20; 
  • AddOleObject, like all other methods of working with MS Office objects, returns OLEVariant - kami
  • And tell me how it turns out: line >> WordApplication1.Selection ... - directly displays the data in "* .doc". And then this function returns the value of a variable that is already resizing. Those. Already after the withdrawal of the object ??? ("horse behind the cart" - it turns out?) - Konstantin78
  • The horse is not in the back :) Before an object is inserted, it does not exist for the word. To change the properties of something, it is necessary that this something appeared. AddOleObject "appears" a new object in the document and returns it for change. For example - you can not change the size of the TForm before you create it? - kami
  • one
    I think that in this way some restrictions in MS Office cost. Again, by analogy with Delphi - if we create a control without binding it to a form (Parent = nil & Owner = nil), then if we try to do something with it, we can get an exception Control has no parent window , since He is trying to redraw, but there’s nothing to draw on ... - kami
  • Of course there are no questions that the properties change after the creation of the object. But somehow it seemed to me that somewhere I needed something like this 1) MyOLEObject: = InlineShapes.AddOLEObject (... - created an object, 2) MyOLEObject.Height .... t.Width: = 20; - the values ​​were applied to it, 3) WordApplication1.Selection ... - they brought it out (the syntax of course is resting, but the course of events is somewhere like that) - Konstantin78