Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Fr 27.02.09 20:37 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
unit convert;

interface
 uses Forms, ShellAPI, Windows;
 procedure ShellExecuteS (WndH : HWND; Operation : String; FileName : String; Parameters : String; Directory : String; CmdShow : Integer);
 procedure BoolToInt(Bool : Boolean; IsBool : Integer; IsNot : Integer);

implementation

procedure ShellExecuteS (WndH : HWND; Operation : String; FileName : String; Parameters : String; Directory : String; CmdShow : Integer);
var OperationW, FileNameW, ParametersW, DirectoryW, Dummy : PWideChar;
begin
  OperationW := StringToWideChar(Operation, Dummy, 255);
  FileNameW := StringToWideChar(FileName, Dummy, 255);
  ParametersW := StringToWideChar(Parameters, Dummy, 255);
  DirectoryW := StringToWideChar(Directory, Dummy, 255);
  ShellExecuteW(WndH, OperationW, FileNameW, ParametersW, DirectoryW, CmdShow);
end;

procedure BoolToInt(Bool : Boolean; IsBool : Integer; IsNot : Integer);
begin
// 'Umwandlung' von Bool in Int
  if(Bool) then
  Result := IsBool
  else // if not(Bool)
  result := IsNot;
end;

end.


Hi DF! Ich habe in ein Projekt eine selbsterstellte Unit auf meinem USB-Stick abgespeichert und nun eingebunden. Allerdings erkennt er die Result-Zuweisung (highlighted!) nicht. Das hier ist die gesamte Unit!

_________________
Die Lösung ist nicht siebzehn.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 27.02.09 20:44 
Benenn Bool mal um in z.B. bBool.
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Fr 27.02.09 20:49 
Hat nicht geklappt, das Problem besteht weiterhin!

_________________
Die Lösung ist nicht siebzehn.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 27.02.09 20:50 
Dann mach aus procedure mal function ;)
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Fr 27.02.09 20:53 
Ah, klar! :autsch:

Danke sehr! :flehan:

_________________
Die Lösung ist nicht siebzehn.
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Fr 27.02.09 22:26 
ma so nebenbei: Gibts das nicht schon?

BoolToString(True) = '1' oder so?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 27.02.09 22:34 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
ma so nebenbei: Gibts das nicht schon?

BoolToString(True) = '1' oder so?

Die Funktion macht doch was ganz anderes - sie gibt den Parameter IsBool zurück, wenn der Boolean True ist, sonst IsNot.

BoolToStr wandelt den als Integer gecasteten Boolean in einen String um; du könntest sie so definieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function BoolToStr(Value: Boolean): String;
begin
  Result := IntToStr(Integer(Value));
end;

Und jetzt vergleich sie mal mit BoolToInt ;)
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Fr 27.02.09 22:48 
ob man nun 1 hat oder "isNot" ist doch wurst wie kartoffel^^
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 27.02.09 22:50 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
ob man nun 1 hat oder "isNot" ist doch wurst wie kartoffel^^


Ein Beispiel:
ausblenden Delphi-Quelltext
1:
Preis := BoolToInt(IsAdult, 63);					


Edit: Beispiel korrigiert


Zuletzt bearbeitet von Yogu am Fr 27.02.09 23:02, insgesamt 1-mal bearbeitet
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Fr 27.02.09 23:00 
Dann ist die Bezeichnung verwirrend, weil die Funktion keinen Boolean zurückgibt sondern einen Gleitkommawert. BoolToFloat oder BoolToInt macht da doch mehr sinn oder?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 27.02.09 23:02 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
Dann ist die Bezeichnung verwirrend, weil die Funktion keinen Boolean zurückgibt sondern einen Gleitkommawert. BoolToFloat oder BoolToInt macht da doch mehr sinn oder?

Sie heißt ja auch BoolToInt, hab mich verschrieben :oops:
dummzeuch
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 593
Erhaltene Danke: 5


Delphi 5 ent, Delphi 6 bis Delphi XE8 pro
BeitragVerfasst: Fr 27.02.09 23:23 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
ma so nebenbei: Gibts das nicht schon?

BoolToString(True) = '1' oder so?


Ja:

ausblenden Delphi-Quelltext
1:
i := IfThen(b, 12);					


twm
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 28.02.09 00:51 
X := IfThen(isAdult, 63); ist eine nette Funktion, die scheinbar wenige kennen, aber das von z.B. PHP bekannte x = (isAdult) ? 6 : 3; ersetzt.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function IfThen(AValue: Boolean; const ATrue: Integer; const AFalse: Integer = 0): Integer; overload;
function IfThen(AValue: Boolean; const ATrue: Int64; const AFalse: Int64 = 0): Int64; overload;
function IfThen(AValue: Boolean; const ATrue: Double; const AFalse: Double = 0.0): Double; overload;
function IfThen(AValue: Boolean; const ATrue: stringconst AFalse: string = ''): stringoverload;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)