Return value of the function might be undefined ???


I have a somewhat lengthy function (see below) which when compiled with BDS2006 always gives me a warning saying that its return value might be undefined. But it says so on a line where Result itself is assigned to ...
Posted On: Tuesday 27th of November 2012 12:57:35 AM Total Views:  352
View Complete with Replies

RELATED TOPICS OF Delphi Programming PROGRAMMING LANGUAGE




Functions that return TStrings

This is a overly simplistic scenario but I hope it explains my question. How does one go about freeing the TStringList created in the ReturnStrings function I've seen routines like this but wonder how to prevent a memory leak. function TForm1.ReturnStrings:TStrings; begin result := TStringList.Create; result.add('Testing'); end; procedure TForm1.Button1Click(Sender:TObject); begin Memo1.Lines.Assign(ReturnStrings); end;
VIEWS ON THIS POST

170

Posted on:

Saturday 22nd September 2012
View Replies!

function return array

, is it possible to write a function that return array of variant \t
VIEWS ON THIS POST

147

Posted on:

Wednesday 3rd October 2012
View Replies!

returning multi-dimentional arrays from functions

Hi: is it possible to return a multidemional array from a function if so how, if not I can pass the array as a parameter to the function. Sean.
VIEWS ON THIS POST

199

Posted on:

Wednesday 3rd October 2012
View Replies!

Is that possible to use function to return a procedural type?

I have a procedural type declare as: type TMyFunc = function(const a, b: integer): integer; And I have 2 functions: function Add(const a, b: integer): integer; begin Result := a + b; end; function Substract(const a, b: integer): integer; begin Result := a - b; end; I then declare a procedure to return one of function above: procedure GetProc(const aFlag: boolean; out aProc: TMyFunc); begin if aFlag then aProc := Add else aProc := Substract; end; I may then use the GetProc as: var P: TMyFunc; i: integer; begin GetProc(True, P); i := P(10, 15); end; The above code runs without as expected. However, if I want to change the GetProc to function that return TMyFunc: function GetFunc(const aFlag: boolean): TMyFunc; begin if aFlag then aProc := Add else aProc := Substract; end; And use it as: i := GetFunc(True)(10, 15); I get a compilation error: "E2066 Missing operator or semicolon". I may only use it as: i := TMyFunc(GetFunc(True))(10, 15); or var P: TMyFunc; i: integer; begin P := GetFunc(True); i := P(10, 15); end; Is this the correct way of using the function to return a procedural type Thank you. -- Best regards, Chau Chee Yang E Stream Software Sdn Bhd URL: www.sql.com.my SQL Financial Accounting
VIEWS ON THIS POST

223

Posted on:

Friday 5th October 2012
View Replies!

XCOPY return code

If this is not the right group, please bear with me. I have an application which calls XCOPY by means of ShellExecute(). Everything works fine but I can't solve the problem of how to receive feedback by the function, i.e. when it has finished its job. ShellExecute(... PChar('xcopy') ...); ShowMessage('Done'); This returns immediately regardless of the copy process still running or not. if ShellExecute(..)
VIEWS ON THIS POST

142

Posted on:

Friday 5th October 2012
View Replies!

D2007 - System.AssignFile Function Example Fails : Readln(F,S) returns extra characters

Hi all, I'm having a lot of trouble with D2007 because the Readln(F,S) function always returns the following extra characters "" at the begining of string. This don't happens before wiht D6. What is going wrong whith this code : procedure TForm1.Edit1Click(Sender: TObject); var F: TextFile; S: string; begin AssignFile(F, 'myFile.Txt'); Reset(F); Readln(F, S); Edit1.Text := S; // ERROR: The Edit1.Text shows "" at the left of the real characters taken from myFile.Txt CloseFile(F); end;
VIEWS ON THIS POST

139

Posted on:

Saturday 6th October 2012
View Replies!

TQuery linked to TUpdate -> Post -> returns to first record.

, I've to create a record and I've a TUpdateSQL linked to a TQuery. Now I've to use the ID (auto_increment field in a mysql table) to create an other record further. The problem is on this code: MyQuery : TQuery; MySecondQuery : TQuery; UpdMyQuery : TUpdateSQL; .... MyQuery.append; myquery.fieldbyname('firstfield').asinteger := somevalue; myquery.fieldbyname('secondfield').asinteger := somothervalue; myquery.post; //further... MySecondQuery.append; MySecondQuery.fieldbyname('linkfield').asinteger := MyQuery.fieldbyname('idfields').asinteger ; The problem is here: If I do myquery.post before this point, I get the first idfields of the MyQuery and If I don't do a Post, I get 0 Before my myquery didn't use a TUpdateSQL as it was on a single table. Now They are joined table so I've to use a TUpdateSQL but when updating, the MyQuery returns on the first record. I want to be able to stay on the new record on the editing record (as sometimes I do edit instead of append).
VIEWS ON THIS POST

134

Posted on:

Tuesday 16th October 2012
View Replies!

Read value out of form's DFM at runtime?

Is there a supported way to read a value out of a form's DFM at runtime The property i'm after is put a published property, but only exists because it was added as a "fake" property using: procedure TCustomForm.DefineProperties(Filer: TFiler); begin ... Filer.DefineProperty('TextHeight', ReadTextHeight, WriteTextHeight, not IsControl); ... end; Now i can't use TStream.ReadComponent TStream.ReadComponentRes or the ReadComponentResEx procedure because these return a component, and the property is not available as a property. Which is why i think there must be a way get at the value of a component's "fake" properties by talking to the component. Something like: TextHeight := Form1.GetDFMProperty('TextHeight'); or Caption := Form1.GetDFMProperty('Caption'); In reality i know there is a zero percent chance of a method like that existing. So then i could get the form's DFM text resource out of my executable directly and either parse it myself, or create a TReader and copy all the guts that loads a form component - but it's not a *correct* way to do things. There would be a case where there's a form that does something i don't expect. (like being the form dfm resource being in binary rather than text). So, is there a *nice* way to read a value out of a form's DFM at runtime
VIEWS ON THIS POST

219

Posted on:

Tuesday 16th October 2012
View Replies!

Subrange Set property accepts enumerated values outside of subrange

I'm having problems with a field that is a set type. The set type is declared as a set of a subrange of an enumerated type. In my code if I try to add another value from the enumeration to the set, it compiles. My feeling is that because the value is outside of the subrange (and hence the allowable types in the set) it should not compile. Any views or explanations are welcome. D type TCTReason = (srStarted, srTimedOut, srTerminated, srSuspended, srResumed); TCTStatusFlag = srStarted .. srTerminated; TCTStatusFlags = set of TCTStatusFlag; .... TCTObject = class private FStatusFlags: TCTStatusFlags; public procedure Update; end; ..... procedure TCTObject.Update; begin // the following line compiles !! It shouldn't because srResumed is outside of the subrange TCTStatusFlag FStatusFlags := FStatusFlags + [srResumed]; end; David Moorhouse Moorhouse Works ltd www.moorhouse.co.nz
VIEWS ON THIS POST

253

Posted on:

Tuesday 16th October 2012
View Replies!

Find the nearest value of an array

, To avoid reinventing the wheel I would like to know in Delphi if such function exists : Let's say I have an array of integer of N values, I have an integer X I need something like Function GetTheIndexOfTheArrayThatHasTheNearestValue(ValueTocompare:integer):integer;
VIEWS ON THIS POST

267

Posted on:

Tuesday 16th October 2012
View Replies!

D2007 - System.AssignFile Function Example Fails : Readln(F,S) returns extra characters

Hi all, I'm having a lot of trouble with D2007 because the Readln(F,S) function always returns the following extra characters "" at the begining of string. This don't happens before wiht D6. What is going wrong whith this code : procedure TForm1.Edit1Click(Sender: TObject); var F: TextFile; S: string; begin AssignFile(F, 'myFile.Txt'); Reset(F); Readln(F, S); Edit1.Text := S; // ERROR: The Edit1.Text shows "" at the left of the real characters taken from myFile.Txt CloseFile(F); end;
VIEWS ON THIS POST

118

Posted on:

Tuesday 16th October 2012
View Replies!

How to over-write values in a log file

Hi , I have a log file I am writing to during a process I am running. Each line lists a table and a value at the end. The value will always be a 3 digit number as in : Start Log At 4:15 PM Table1 026 Table2 056 What I need to do is update the value as the process runs. But I don't know how many times the number will be updated. So what I want to do is write the value, and then if it is updated, write the new value over the top of the old one. How can I do this. I am using TextFiles and using Append to add to the file. In the above example, if a new value for Table2 was received, I want to over-write the 056 and replace it with 078 (or what ever). I will only ever update the last table in the log file. Once I move to another table, the previous table is finished with. And I'll write the value with Write (and not WriteLn). Any ideas how I can do this Cheers, Paul
VIEWS ON THIS POST

203

Posted on:

Tuesday 16th October 2012
View Replies!

canvas.textheight return value problem

canvas.textheight(str) always seems to return the same value, regardless of the string parameter used. That is, except for '' (where it returns 0), using 'jT' or '.' makes no difference. what could be wrong Frank. PS: I'm trying to 'correct' canvas.TextWidth when using fsItalic
VIEWS ON THIS POST

327

Posted on:

Tuesday 16th October 2012
View Replies!

Saving list box values to the registry

Hi , whats the best way to save a list boxes values to the registry. I know I could cycle through each one, but i think there's a better way. Any ideas Cheers, Paul...
VIEWS ON THIS POST

168

Posted on:

Saturday 10th November 2012
View Replies!

Append carriage return/line feed in a string

I got a string, say 'Goodbye' I want to append the carriage return AND also line feed character at the end. How do I do that
VIEWS ON THIS POST

202

Posted on:

Thursday 22nd November 2012
View Replies!

strange conversion result value code = 2

, Using value(string, zahl, code) I am used to get 0 for a successful conversion and 1 for a negativ result. But this time, using 'EA' as string (Electron) I got the result code := 2 !!! What does this ...
VIEWS ON THIS POST

158

Posted on:

Thursday 22nd November 2012
View Replies!

Set as integer value

Alexander Halser wrote: > I need to save a set as an integer value and I would like to convert > this more easyily than I do now. The set is a set of constants, > something like this: > ...
VIEWS ON THIS POST

102

Posted on:

Sunday 25th November 2012
View Replies!

COM+ returns empty olevariant if properties was set

all, I fetch data from the SQL Server and pass them to client application with TClientDataSet, at the same time I would also like to set the properties of the COM+ interface, but to my surprise, the COM+ would ...
VIEWS ON THIS POST

130

Posted on:

Sunday 25th November 2012
View Replies!

Checking bit value from an integer

How do i get a value of a certain bit from a 32bit integer For example i want to get the value of the 30th bit from this lParam: lParam [in] Specifies the repeat count, scan code, extended-key flag, context ...
VIEWS ON THIS POST

105

Posted on:

Sunday 25th November 2012
View Replies!