Can Someone Solve the mistery of this function please

the code below which is probably written in delphi 4 gives this error
[DCC Error] PCI.PAS(86): E2010 Incompatible types: 'Boolean' and 'Byte'
[DCC Error] PCI.PAS(68): E2004 Identifier redeclared: 'Result'
could someone help me to solve it please
function readPCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:byte):boolean;
var okay:boolean;
    res:byte;
begin
  okay:=false;
  res:=0;
  asm
    db 66h; pusha
    mov AX,0B108h
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    int 1Ah
    jc @noaction
    mov res,cl
    mov okay,true
  @noaction:
    db 66h; popa
  end;
  result:=res;
  readPCIRegisterByte:=okay;
end;

Open in new window

fatihbarutAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
rename tha var result;

Resulr is already declared into the function as byte but the function result is a boolean value
That's why it says [DCC Error] PCI.PAS(86): E2010 Incompatible types: 'Boolean' and 'Byte'

so the correct one could be
function readPCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var InternalResult:byte):boolean;
var okay:boolean;
    res:byte;
begin
  okay:=false;
  res:=0;
  asm
    db 66h; pusha
    mov AX,0B108h
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    int 1Ah
    jc @noaction
    mov res,cl
    mov okay,true
  @noaction:
    db 66h; popa
  end;
  InternalResult := res;
  readPCIRegisterByte:=okay;
end;

0
fatihbarutAuthor Commented:
It solved my problem thanks
However before accept the solution just one more consideration.
What if someone calls the result from out side of the function.
You know, normally result refers the actual output of the function.
do you think it may cause confliction?
0
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
well, a function result is of course the result of the function itself, so for definition "Result" become reserved word for this case.
Using this word assigning it to a variable can of course cause a conflict, and that's why modern compilers give errors in this case.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fatihbarutAuthor Commented:
so how can I solve this confliction without ruin the function of the function? This is the matter.
0
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
You could turn the Extended Syntax  to off
Adding {$X-} to your unit you can turn off the Extended Syntax and let the compiler use the "Result" var as it is, without checking it syntax.
But be aware about any other syntax check. the best way could be to turn it off before the function and turn it on again at the end

From delphi Help:

Remarks

Note: The $X directive is provided for backward compatibility. You should not use the {$X-} mode when writing Delphi applications.
The $X directive enables or disables Delphi's extended syntax:

Function statements. In the {$X+} mode, function calls can be used as procedure calls; that is, the result of a function call can be discarded, rather than passed to another function or used in an operation or assignment. Generally, the computations performed by a function are represented through its result, so discarding the result makes little sense. Sometimes, however, a function is called because it performs a task such as setting the value of a global variable, without producing a useful result.
The Result variable. In the {$X+} mode, the predefined variable Result can be used within a function body to hold the function's return value.
Null-terminated strings. In the {$X+} mode, Delphi strings can be assigned to zero-based character arrays (array[0..X] of Char), which are compatible with PChar types.
This directive also affects the use of the caret (^) to indicate pointers. When {$X+} is in effect (the default), you can omit the caret when referencing pointers. When declaring a pointer, however, the caret is required.


As I already said, this way you could solve your conflict's question, but it could generate lot of other matters into your code. I'd stay to the variable's renaming solution.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fatihbarutAuthor Commented:
Yes I think this is the solution, compiler made no complain after I added {$X-}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.