Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Прочее";
Текущий архив: 2007.04.15;
Скачать: [xml.tar.bz2];

Вниз

Помнится, тут уже было несколько соревнований...   Найти похожие ветки 

 
Empleado ©   (2007-03-22 19:30) [0]

Предложите интересные реализации проверки условия, типа if not MyBool <> True then. На любом языке.
Спасибо


 
Ega23 ©   (2007-03-22 19:33) [1]


function ConvertBooleanValue(const Value : Boolean) : Boolean;
begin
 if (Value=True) then
  begin
   Result := False;
  end
 else
  if (Value=False) then
   begin
    Result := True;
   end
  else
   raise Exception.Create("Unknuwn boolean value!");
end;


 
umbra ©   (2007-03-22 19:38) [2]

function ConvertBooleanValue(const Value : Boolean) : Boolean;
begin
Result := not Value;
end;


 
Vlad Oshin ©   (2007-03-22 19:38) [3]

не понял...
так что ли?
if MyBool <> false then
if MyBool = true then


 
Ega23 ©   (2007-03-22 19:38) [4]


> umbra ©   (22.03.07 19:38) [2]


фи...


 
Vlad Oshin ©   (2007-03-22 19:41) [5]

в чем прикол то


 
umbra ©   (2007-03-22 19:41) [6]

2 Ega23 ©   (22.03.07 19:38) [4]

я, наверное, не понял, какие реализации называются интересными :)


 
oldman ©   (2007-03-22 19:42) [7]


> Empleado ©   (22.03.07 19:30)  
> Предложите интересные реализации проверки условия, типа
> if not MyBool <> True then. На любом языке.


Предлагаю.
На Паскале:

if not MyBool <> True then

:)))


 
Ega23 ©   (2007-03-22 19:43) [8]


> я, наверное, не понял, какие реализации называются интересными
> :)
>


Да тут месяца с три назад соревнование в маразме было...  :)


 
Empleado ©   (2007-03-22 19:44) [9]


> umbra ©   (22.03.07 19:41) [6]

"интересные" - в кавычках :)

> Ega23 ©   (22.03.07 19:33) [1]

Сильно :)


 
oldman ©   (2007-03-22 19:46) [10]


> Ega23 ©   (22.03.07 19:33) [1]


А через case не сработает?


 
Ega23 ©   (2007-03-22 19:48) [11]


> А через case не сработает?


Так маразматичнее. ИМХО. :)


 
Eraser ©   (2007-03-22 19:48) [12]

вот наваял )
function ConvertBooleanValue(const Value : Boolean) : Boolean;
var
 str: string;
begin
 try
   str := BoolToStr(Value, true);
   if Length(str) > 4 then
     Result := not Value
   else
     if Length(str) = 4 then
       Result := not Value
     else
       raise Exception.Create("Unknuwn boolean value!");
 except
   raise Exception.Create("Unknuwn boolean value!");
 end;
end;


 
Vlad Oshin ©   (2007-03-22 19:49) [13]

надо набрать в поисковике Правила булевой алгебры и по формулам раскрутить А=В на пару пейджов


 
Empleado ©   (2007-03-22 19:53) [14]


> Eraser ©   (22.03.07 19:48) [12]

В твоем коде ошибка! :)


 
Eraser ©   (2007-03-22 19:55) [15]

> [14] Empleado ©   (22.03.07 19:53)

хз, у меня работает )


 
Empleado ©   (2007-03-22 19:58) [16]


> Eraser ©   (22.03.07 19:55) [15]

"Unknuwn" :)


 
Ega23 ©   (2007-03-22 19:59) [17]

да и raise 2 раза - лишнее...


 
Eraser ©   (2007-03-22 20:01) [18]

> [16] Empleado ©   (22.03.07 19:58)

значит не та версия Делфи, у меня такой код
 if ConvertBooleanValue(true) then
   ShowMessage("!!!");
 if ConvertBooleanValue(false) then
   ShowMessage("!!!");

работает как надо )

> [17] Ega23 ©   (22.03.07 19:59)

так надо, чтобы программа надежнее работала )


 
umbra ©   (2007-03-22 20:07) [19]

interface

type
 TBooleanConverter = class
  private
    FValue: Boolean;
  public
     constructor Create(Value: Boolean); reintroduce;
     property Value: boolean read FValue;
  end;

implementation

constructor TBooleanConverter.Create(Value: Boolean);
begin
 inherited Create;
 if Value <> True then
   FValue := True
 else
   FValue := False;
end;


Использовать так:

with TBooleanConverter.Create(myBoolean) do
 try
   if Value then {......};
 finally
   Free;
 end;


 
easy ©   (2007-03-22 20:13) [20]

http://bash.org.ru/quote.php?num=66390


 
Eraser ©   (2007-03-22 20:19) [21]

> [20] easy ©   (22.03.07 20:13)


> if (b.ToString().length < 5){...}

ну на делфи код еще извращеннее получается )
if Length(BoolToStr(b, True)) < 5 then


 
Knight ©   (2007-03-22 21:50) [22]

if StrToInt(BoolToStr(MyBool, MyBool and not MyBool))<StrToInt(BoolToStr(not MyBool, MyBool and not MyBool)) then


 
VirEx ©   (2007-03-22 22:38) [23]

procedure to_be;
function be(to_be:boolean):boolean;
begin
 result:=to_be or not to_be
end;
begin
if messagebox(0,PChar(""+vartostr(be(boolean(1-random(2))))),"to be or not to be?",IDOK)<>IDHELP then to_be
end;


 
DrPass ©   (2007-03-22 23:04) [24]

А вот без всяких выдумок, вполне тривиальный код на RPG-III:
*IN80 IFEQ*OFF


 
BiN ©   (2007-03-22 23:04) [25]

эх, вы.... учитесь пока я жив ))

function NotBool(Value: Boolean): Boolean;
var
 Temp: Boolean;
begin
 for Temp:=Low(Boolean) to High(Boolean) do
   If Temp xor Value then
   begin
     Result:=Temp;
     Exit;
   end;
 raise Exception.Create("Chaos Error: Invalid entropy direction");
end;


 
Игорь Шевченко ©   (2007-03-22 23:07) [26]

BiN ©   (22.03.07 23:04) [25]

Потрясающе!


 
BiN ©   (2007-03-22 23:09) [27]


> Игорь Шевченко ©   (22.03.07 23:07) [26]

Спасибо, не стоит )


 
VirEx ©   (2007-03-23 00:38) [28]

library GetBool;

uses
 SysUtils,
 Classes,
 windows;

const
TBoolStr : array[0..1] of string=("True","False");

type
TBoolType = (IsBoolean, IsNotBoolean);
TResult   = procedure (result:string) of object;

TBoolParser = class(TObject)
 FBool_:integer;
 constructor create;
 destructor  destroy;
 function GetBoolType:TBoolType;
 property Bool_: integer read FBool_ write FBool_;
end;

type
 TBooler = class(TThread)
 private
 FBool:string;
 //FBoolRes:TBoolStr;
 FParser:TBoolParser;
 FOnResult:TResult;
 protected
  procedure Execute; override;
 public
  constructor Create(s:string);
 published
  property OnResult: TResult read FOnResult write FOnResult;
end;

var
Booler:TBooler;

function IsBooleanOrNotBool(s:string;r:TResult):string;
begin
if Booler<>nil then Booler.Destroy;
Booler:=TBooler.Create(s);
Booler.OnResult:=r;
Booler.Resume;
end;

function IsRealyBoolean(b:boolean;r_:TResult):boolean; export
begin
 IsBooleanOrNotBool(IntToStr(Integer(b)),r_);
end;

constructor TBooler.Create(s: string);
begin
FBool:=s;
FParser:=TBoolParser.create;
with FParser do Bool_:=StrToInt(s);
inherited Create(True);

end;

procedure TBooler.Execute;
begin
 inherited;
 case FParser.GetBoolType of
 IsBoolean   :FOnResult(TBoolStr[0]);
 IsNotBoolean:FOnResult(TBoolStr[1]);
 end;
end;

{ TBoolParser }
constructor TBoolParser.create;
begin
FBool_:=0;
inherited Create;
end;

destructor TBoolParser.destroy;
begin
FBool_:=-1;
end;

function TBoolParser.GetBoolType: TBoolType;
begin
case FBool_ of
1:result:=IsBoolean;
0:result:=IsNotBoolean;
end;
end;

exports
 IsRealyBoolean;

begin
end.

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TResult = procedure (s:string) of object;

 TForm1 = class(TForm)
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 procedure Result(s: string);
 end;

var
 Form1: TForm1;

 function IsRealyBoolean(b:boolean;r_:TResult):boolean; external "GetBool.dll" name "IsRealyBoolean";
implementation

{$R *.dfm}
procedure TForm1.Result(s: string);
begin
MessageBox(0,PChar(s),"result",id_ok);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
IsRealyBoolean(true,Result);
end;
end.


 
Knight ©   (2007-03-23 00:59) [29]

if MessageDlg(UpperCase(BoolToStr(MyBool,True))+"=TRUE?",mtConfirmation,[mbYes,mbNo],0)=mrYes then ;


 
Gero ©   (2007-03-23 01:51) [30]

(***********************************************************)
(*                                                         *)
(*           TrueChecker.pas &#151; TTrueChecked Component      *)
(*                                        Version 1.0      *)
(*                                                         *)
(*                 Copyright © 2006 by Yanis Prasol      *)
(*                 All rights reserved.                    *)
(*                                                         *)
(***********************************************************)

unit TrueChecker;

interface

uses
Classes, SysUtils;

const
TrueValue = True;
NonTrueValue = not True;

type
TTrueFalseChanger = class(TObject)
public
 procedure SetTrue(var X: Boolean);
 procedure SetNonTrue(var X: Boolean);
 procedure SetNonTrueIfTrueAndSetTrueIfNonTrue(var X: Boolean);
end;

TTrueChecker = class(TComponent)
private
 FVariable: Boolean;
 function GetIsTrue: Boolean;
 procedure SetVariable(const Value: Boolean);
public
 constructor Create(AOwner: TComponent); override;
published
 property IsTrue: Boolean read GetIsTrue;
 property Variable: Boolean read FVariable write SetVariable default NonTrueValue;
end;

implementation

const
STrueSettingError = "Failed set variable value to true!";
SNonTrueSettingError = "Failed set variable value to non true!";
SNonTrueAndNonFalseError = "Boolean variable value is not true and not false!";
SDontUnderstandingError = "mmmmmmmmmmm&#133?";

{ TTrueFalseChanger }

procedure TTrueFalseChanger.SetTrue(var X: Boolean);
begin
repeat
 if (X <> TrueValue) or (X = NonTrueValue) then
   begin
     SetNonTrueIfTrueAndSetTrueIfNonTrue(X);
   end
 else
   raise Exception.Create(STrueSettingError);
until X = TrueValue;
end;

procedure TTrueFalseChanger.SetNonTrue(var X: Boolean);
begin
repeat
 if (X <> NonTrueValue) or (X = TrueValue) then
   begin
     SetNonTrueIfTrueAndSetTrueIfNonTrue(X);
   end
 else
   raise Exception.Create(SNonTrueSettingError);
until X = NonTrueValue;
end;

procedure TTrueFalseChanger.SetNonTrueIfTrueAndSetTrueIfNonTrue(var X: Boolean);
begin
if (X <> (X and not X)) = TrueValue then
 begin
   X := NonTrueValue;
 end
else if (X xor NonTrueValue) = NonTrueValue then
 begin
   X := TrueValue;
 end
else
 raise Exception.Create(SNonTrueAndNonFalseError);
end;

{ TTrueChecker }

function TTrueChecker.GetIsTrue: Boolean;
label
TrueLabel, FalseLabel;
var
TrueFalseChanger: TTrueFalseChanger;
begin
TrueFalseChanger := TTrueFalseChanger.Create;
try
 try
   if (FVariable = TrueValue) and (FVariable <> NonTrueValue) then
     begin
       goto TrueLabel;
     end
   else
     begin
       if (FVariable = NonTrueValue) and (FVariable <> TrueValue) then
         begin
           goto FalseLabel;
         end
       else
         raise Exception.Create(SDontUnderstandingError);
     end;
   TrueLabel:
   while (Result <> TrueValue) do
     TrueFalseChanger.SetTrue(Result);
   Exit;
   FalseLabel:
   while (Result <> NonTrueValue) do
     TrueFalseChanger.SetNonTrue(Result);
   Exit;
 except
   Result := NonTrueValue;
 end;
finally
 TrueFalseChanger.Free;
end;
raise Exception.Create(STrueSettingError);
end;

constructor TTrueChecker.Create(AOwner: TComponent);
begin
inherited;
FVariable := NonTrueValue;
end;

procedure TTrueChecker.SetVariable(const Value: Boolean);
begin
if FVariable <> Value then
 FVariable := Value;
end;

end.


Пример использования:

procedure TForm1.Button1Click(Sender: TObject);
const
TestedValiable = True;
var
TrueChecker: TTrueChecker;
ResultValiable: Boolean;
begin
TrueChecker := TTrueChecker.Create(nil);
try
 TrueChecker.Variable := TestedValiable;
 ResultValiable := TrueChecker.IsTrue;
 if ResultValiable then
   ShowMessage("Variable is True!")
 else
   ShowMessage("Variable is False!");
finally
 TrueChecker.Free;
end;

end;


 
Германн ©   (2007-03-23 02:04) [31]

Это что? Соревнование в "переплюнивании" той самой функции IncDay?
:)


 
Loginov Dmitry ©   (2007-03-23 07:52) [32]

Что-то должно нету варианта с COM :)


 
Hero ©   (2007-03-23 09:49) [33]

валяюсь :DDDDDD


 
REA   (2007-03-23 09:56) [34]

А ведь еще не раскрыта тема SomeVar := Not(True = False) = True xor (Var = NotVar)...


 
REA   (2007-03-23 10:02) [35]

TExBoolean = (eTrue, eFalse, eIDontKnow, eIDontCare, eWhatIsThisFor, eSeemsTrue, eSeemsNotTrue, eNotKnownYet, eNeverTellSomeoneButItsTrue)


 
Virgo_Style ©   (2007-03-23 10:10) [36]

Мне кажется, гораздо изящнее будет после BoolToStr использовать регэкспы...


 
Gadenysh   (2007-03-23 12:22) [37]

через варианты можно сделать. и в сеттер\геттер - запись\чтение из файла. код лень писать))


 
Gadenysh   (2007-03-23 12:24) [38]


> Gero ©   (23.03.07 01:51) [30]


а где иконко в трее? не годится


 
Knight ©   (2007-03-23 13:39) [39]

А где сетевые технологии, зачатки ИИ... и прочее? :)


 
Карелин Артем ©   (2007-03-23 13:58) [40]

   public sealed class BeeChanger
   {
       public static bool toBee(bool Bee)
       {
           return (Bee.ToString().Equals(bool.TrueString));
       }

       public static bool nottoBee(bool Bee)
       {
           return (Bee.ToString().Equals(bool.FalseString));
       }
   }



Страницы: 1 2 вся ветка

Форум: "Прочее";
Текущий архив: 2007.04.15;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.56 MB
Время: 0.062 c
2-1174495935
T.V
2007-03-21 19:52
2007.04.15
Вопрос по var-параметрам и указателям


2-1175150239
Alex7
2007-03-29 10:37
2007.04.15
Как дать команду Windows XP открыть заданный файл


15-1174410324
@!!ex
2007-03-20 20:05
2007.04.15
Препод сказал: Возражаю.


15-1174410706
@!!ex
2007-03-20 20:11
2007.04.15
Интернет заработок.


1-1172067206
sia
2007-02-21 17:13
2007.04.15
что находится под курсором мыши?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский