![]() |
(SST) ShlWAPIFunctionInfo Version 1.0 |
---|---|
Developer Reference |
Assigns an error code to member variable flasterror. This is the error code returned when reading property LastError. |
Scope |
---|
Protected (i.e. the method can only be accessed from code in a descendant class or the unit it which it is implemented). |
Syntax | |
---|---|
Procedure SetLastErrorCode(adeferrorcode : INTEGER); VIRTUAL; |
Parameters | |
---|---|
adeferrorcode [in] |
A signed, 32 bit, integer value to return to potential callers/readers of property LastError
that indicates whether or not an error occurred during the last call of a TSSTDllVerInfo method.
This is the value assigned to member variable flasterror in the event that the Windows API function GetLastError can't, or no longer, returns a meaningful error code.
Rephrase !!! Ideally, this value also provides some form of indication on the nature of the error. |
Return Values |
---|
This function does not return a value. |
Remarks | ||||||
---|---|---|---|---|---|---|
The procedure calls the Windows API function GetLastError to retrieve the error code of the last error that occurred in the context of the calling thread. If GetLastError returns NO_ERROR (= 0), SetLastErrorCode assigns the value specified in parameter adeferrorcode to member variable flasterror, otherwise the value returned by GetLastError. | ||||||
Unless an error is detected prior to invoking a Delphi SDK or Windows API function, for example, the invalid initialization of the object's member variables, this procedure (SetLastErrorCode) should be the preferred method for assigning error codes to member variable flasterror. | ||||||
The functionality of this method was inspired by the Delphi SDK function "StrToIntDef".
It is intended to ensure that an error code can be retrieved by the instantiating function(s), in the event that one is caused by the TSSTDllVerInfo class's code.
This is necessary to prevent the Delphi SDK's built-in error handling mechanism(s)
from handling errors and converting them into exceptions that may cause a cascade of error dialog boxes to be displayed, while preventing the Windows API function GetLastError from returning a meaningful error code.
Although this could also be achieved by several other methods, the simplest of
which is, to set the global, Delphi SDK, variable "NoErrMsg" to TRUE, this would
also impose unnecessary restrictions on the implementation of the code that uses TSSTDllVerInfo objects.
Unfortunately, the current, simple, implementation is only entirely reliable if the Windows API function SetLastError is called to reset the thread local storage's (TLS) last error code, prior to invoking any TSSTDllVerInfo methods, as otherwise, the TSSTDllVerInfo LastError property might erroneously return an error caused by wholly unrelated code. Furthermore, the current implementation also requires that external functions that may cause errors are not called between calls to the class's methods. The following code exemplifies the issue.
|
||||||
|
||||||
|
||||||
The procedure does not perform any checks to determine from which thread the last error code is being retrieved and assigned to flasterror (i.e. in multi-threaded applications, it is up to the caller to ensure that the error is retrieved from the correct thread). | ||||||
Under Vista (with SP 1 & IE 8), if the Windows API function VerQueryValue fails due to a predefined version information string-name not being present in the file's resources, it sets the last error code stored in thread local storage (TLS) to ERROR_RESOURCE_TYPE_NOT_FOUND (= 1813), although ERROR_RESOURCE_NAME_NOT_FOUND (= 1814) would be more appropriate. |
Requirements | |
---|---|
Unit | (Declared and implemented in) SSTNewUnit.pas |
Library | SSTNewUnit.dcu/SSTNewUnit.obj |
Unicode | Implemented as ANSI version only. |
See Also |
---|
TSSTDllVerInfo, LastError, flasterror, Source Code |
Windows APIs: GetLastError, SetLastError. |
Document/Contents version 1.00 Page/URI last updated on April 30, 2022 |
Copyright © Stoelzel Software Technologie (SST) 2010 - 2017 |
Suggestions and comments mail to: webmaster@stoelzelsoftwaretech.com |