Rave-report beforeprint event memory leak - memory-leaks

I have this code in the event "DatabandBeforePrint" :
self.visible := not ((dvMatCommesseLavorazione.asstring = 'TAGLIO TRONCATRICE')
or (dvMatCommesseLavorazione.asstring = 'TAGLIO SEZIONATRICE')
or (dvMatCommesseLavorazione.asstring = 'TAGLIO PANTOGRAFO') );
When I close the application, why do I get a "Memory leak" from madexcept.
memory leak
Is there anyone that could explain me why this occurs?
Thanks for any helps.

I think this occurs because Rave vs Delphi WideString issues. You can workaround it adding and filling a boolean or integer field according your business rule. Checking an integer or boolean field would avoid WideString comparison. I read somewhere that new versions of Rave does correct this issues.

Related

DOORS Attribute DXL Resource releasing? which do I need to release?

Hi I'm a bit uncertain about good practice within IBM DOORS Attribute DXL when it comes to which resources to release?
// I believe the following is correct for assigning the value of a buffer to an attribute of type Text.
Buffer buff = create
buff = "hello"
delete(buff)
obj.attrDXLName = tempStringOf(buff)
delete(buff)
// strings - what is required?
// eg..
string s = "hello"
s = "hello world"
s = null
// Where I am navigating through links, I may be using the following
LinkRef myLinkRef = null
myLinkRef = ...
ModName_ otherModuleHandle = data(SourceVersion myLinkRef)
Module m = ...
delete(otherModuleHandle)
In Attribute DXL, Which handles are known to need to be free'd and whats the best way to release the resource. I've seen delete(otherModuleHandle) being used, but not sure how it works or why it is needed.
I have a suspicion that DOORS DXL does some sort of reference counting in its memory model.
Any thoughts would be greatly appreciated.
I think the code listed will throw several errors?
Example- you can't refer to a buffer after calling delete on that buffer (your line 3).
If you asking about freeing up resources, that's a good practice for attribute dxl (which needs to essentially run the code for each object in the module when the module opens / the attribute is refreshed) - however, I wouldn't bother with setting strings to null. I would clean up used buffers at the end of my script, and I might close open module handles depending on what I was doing with them. On the other hand, I might leave the module handles, especially if I'm opening it multiple other times, as I have occasionally bumped into issues with code that opens / closes modules repeatedly.

Simple Sleep() not working in VC++

I am working on a project than involves making an image appear and then disappear after a fixed time. I thought that the correct function for that purpose would be Thread::Sleep() but it doesn't seem to work.
this->pictureTConf->Visible = true;
Thread::Sleep(5000);
this->pictureTConf->Visible = false;
With this code, the picture doesn't appear at any moment. Any thoughts? Thanks.
PD: Using Visual Studio, Windows forms and VC++.
Setting a member variable to true isn't enough because your call to Sleep() prevents the code from running the message loop. Try this instead: (This is just for sample purposes, you shouldn't do this in a "real" application.)
this->pictureTConf->Visible = true;
this->pictureTConf->Refresh();
Thread::Sleep(5000);
this->pictureTConf->Visible = false;
this->pictureTConf->Refresh();
Also, as Chuck pointed out, if you use a timer, you shouldn't need the calls to Refresh(). Everything will just work.

Delphi 7 with..do statement doesen't work with variant variable

I'm working with Microsoft Excel via Delphi 7. It works fine but while formatting rows and ranges I have to write such long strings.
XLApp.Workbooks[1].WorkSheets[NameDoc].Range['A19:L19'].Font.Bold := true;
So I want to get rid of hard work and do it via "with..do" statement like this
with XLApp.Workbooks[1].WorkSheets[NameDoc] do
begin
Range['A19:L19'].Font.Bold := true;
end;
But at compilation stage I see this error
Record, object or class type required
on string - "with..do".
I creating Excel object this way
XLApp: Variant;
XLApp := CreateOleObject('Excel.Application');
I consider that with..do statement doesen't works with variant type variable, but I want to know whether I'm right or not? And if I'm right is there any workaround to make it work?
Variant can be anything or nothing at all - compiler doesn't know it and cannot know: it is so called "dynamically typed value". Since it does not know - it does not know if there would be any members (properties, methods) and if there would - what names would they have.
To get the benefits of strong compile-time typing - including using of with but not only - you have to use interface variables, those that are provided by TExcelApplication component and underlying unit having those values "statically typerd" - thus providing for Delphi compiler to know value types when compiling, in before running. There are plenty of types like iWorsksheet, iRange and others in that unit.
Borland Delphi 7 TExcelApplication.Connect works on office machines but not at client
http://www.delphipages.com/forum/showthread.php?t=157889
http://delphikingdom.ru/asp/viewitem.asp?catalogid=1270
However, since that is about reference-counting and lifetime I'd suggest you go with explicit use of temp variables rather than using with with and implicit invisible variables. Since you cannot control their lifespan and their clearance you might hit the wall in some unexpected place later. I did.
var tmpR: iRange; // assuming we have statically-typed API
// for example - providing we using ExcelXP or Excel2000 unit
tmpR := XLApp.Workbooks[1].WorkSheets[NameDoc];
tmpR.Range['A19:L19'].Font.Bold := true; // instead of with
with tmpR do // also possible but gives little benefit now
begin // when we made a dedicated temp var
Range['A19:L19'].Font.Bold := true;
end;
tmpR := nil; // crucial unless the most short and simplistic functions
// just release hold on Excel's object - let it manage its memory freely,
// by letting Excel know your program no more uses that object.
Also read
https://en.wikipedia.org/wiki/Automatic_Reference_Counting
https://en.wikipedia.org/wiki/Component_Object_Model
Can with be used with a Variant?
No.
You can use with for types whose members are known at compile time. But variants, for which the . operator is evaluated at run time, do not fall into this category. Hence with is not available for variants.
The documentation says, with my emphasis:
A with statement is a shorthand for referencing the fields of a record
or the fields, properties, and methods of an object. The syntax of a
with statement is:
with obj do statement
or:
with obj1, ..., objn do statement
where obj is an expression yielding a reference to a record, object
instance, class instance, interface or class type (metaclass)
instance, and statement is any simple or structured statement.

Using CoWaitForMultipleHandles

Continuing from
Pausing execution of a Thread WITHOUT sleeping?
How do I use the CoWaitForMultipleHandles routine, as Lars Truijens suggested? I found the routine in the SyncObjs unit, however I get "undeclared identifier" when trying to call it? The IDE Insight does not bring anything up either? And yes, I have added SyncObjs to my Uses clause.
I can't see what other info I need to include - however feel more than free to ask for more info!
You can't call this function from SyncObjs, because it hasn't been declared in interface section. But TEvent.WaitFor actually calls CoWaitForMultipleHandles. Did you try it?
And please note its constructor declaration:
{ Specify UseCOMWait to ensure that when blocked waiting for the object
any STA COM calls back into this thread can be made. }
constructor Create(UseCOMWait: Boolean = False);

SharePoint and thread safety

I'm looking for articles, forum or blog posts dealing with SharePoint and thread safety? I'm quite sure there are some special aspects regarding thread safety that have to be considered when working with the SharePoint object model.
Actually I didn't find many information about this, yet.
So I'm looking forward to your answers.
Bye,
Flo
There are much worse pitfalls in the SharePoint OM than just plain old thread safety. Pay particular attention to working with objects retrieved from properties. You should always keep a pointer to an object while you work on it; example:
var list = web.List["MyList"]
list.Items[0]["Field1"] = "foo"
list.Items[0]["Field2"] = "bar"
list.Items[0].Update() // nothing is updated!
You might expect Field1 and Field2 to be updated by the final Update() call, but nope. Each time you use the indexer, a NEW reference to the SPListItem is returned.
Correct way:
SPListItem item = list.Items[0]
item["Field1"] = "foo"
item["Field2"] = "bar"
item.Update() // updated!
Just a start. Also google for pitfalls around the IDisposabe/Dispose pattern.
-Oisin
There is one issue that I often run into: when writing your own list item receivers, you need to be aware of the fact that some of the events fire asynchronously, e.g. ItemAdded() which means your code could be running in multiple threads at the same time.
So after doing some more googling and searching on the web and testing, it seems as if you don't have to care about thread-safety that much when using the MOSS object model because you're always working with non-static and unique instances.
Furthermore an exception is thrown when a object e.g. a SPWeb was altered and saved by calling the Update() method before you saved your changes (also calling the Update() method) even though you got your object first.
In the following example the instruction web11.Update() will throw an exception telling you that the SPWeb represented through the object web12 was altered meanwhile.
SPSite siteCol1 = new SPSite("http://localhost");
SPWeb web11 = siteCol1.OpenWeb();
SPWeb web12 = siteCol1.OpenWeb();
web12.Title = "web12";
web12.Update();
web11.Title = "web11";
web11.Update();
So the thready-safety seems to be handled by the object model itself. Of course you have to handle the exceptions that might be thrown due to race conditions.

Resources