unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
StdCtrls;
type
{ TForm2 }
TForm2 = class(TForm)
Button1: TButton;
cb1_input1: TComboBox;
cb4_input1: TComboBox;
cb4_input2: TComboBox;
cb4_schaltung: TComboBox;
cb1_input2: TComboBox;
cb1_schaltung: TComboBox;
cb2_input1: TComboBox;
cb2_input2: TComboBox;
cb2_schaltung: TComboBox;
cb3_input1: TComboBox;
cb3_input2: TComboBox;
cb3_schaltung: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
private
public
{***************************MACROS AND PREPROCESSORS***************************}
{$MACRO ON}
{$define IDENTITY := NOT NOT}
{$define NEGATION := NOT} //(not)
{$define CONJUNCTION := AND} //(and)
{$define ALTERNATIVE := OR} //(or)
{$define NEGATIV_CONJUNCTION := NAND} //(nand) disjunction
{$define NEGATIV_ALTERNATIVE := NOR} //(nor)
{$define REMOVABLE_ALTERNATIVE := XOR} //(xor)
{$define OPERATOREN}
end;
var
Form2: TForm2;
z1, z2, z3, z4, e1, e2, e3, e4, e5, e6, e7, e8 : Array of Integer; //beetwen_outputs and inputs in all of connections
i,j,k,l,m : Integer; //iteration for loops
implementation
{$R *.lfm}
{ TForm2 }
procedure preprozessors;
begin
if((Form2.cb1_schaltung.Text='IDENTITY') OR (Form2.cb2_schaltung.Text='IDENTITY')
OR (Form2.cb3_schaltung.Text='IDENTITY') OR (Form2.cb4_schaltung.Text='IDENTITY')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := IDENTITY}
end;
if((Form2.cb1_schaltung.Text='NEGATION') OR (Form2.cb2_schaltung.Text='NEGATION')
OR (Form2.cb3_schaltung.Text='NEGATION') OR (Form2.cb4_schaltung.Text='NEGATION')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := NEGATION}
end;
if((Form2.cb1_schaltung.Text='CONJUNCTION') OR (Form2.cb2_schaltung.Text='CONJUNCTION')
OR (Form2.cb3_schaltung.Text='CONJUNCTION') OR (Form2.cb4_schaltung.Text='CONJUNCTION')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := CONJUNCTION}
end;
if((Form2.cb1_schaltung.Text='ALTERNATIVE') OR (Form2.cb2_schaltung.Text='ALTERNATIVE')
OR (Form2.cb3_schaltung.Text='ALTERNATIVE') OR (Form2.cb4_schaltung.Text='ALTERNATIVE')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := ALTERNATIVE}
end;
if((Form2.cb1_schaltung.Text='NEGATIV_CONJUNCTION') OR (Form2.cb2_schaltung.Text='NEGATIV_CONJUNCTION')
OR (Form2.cb3_schaltung.Text='NEGATIV_CONJUNCTION') OR (Form2.cb4_schaltung.Text='NEGATIV_CONJUNCTION')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := NEGATIV_CONJUNCTION}
end;
if((Form2.cb1_schaltung.Text='NEGATIV_ALTERNATIVE') OR (Form2.cb2_schaltung.Text='NEGATIV_ALTERNATIVE')
OR (Form2.cb3_schaltung.Text='NEGATIV_ALTERNATIVE') OR (Form2.cb4_schaltung.Text='NEGATIV_ALTERNATIVE')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := NEGATIV_ALTERNATIVE}
end;
if((Form2.cb1_schaltung.Text='REMOVABLE_ALTERNATIVE') OR (Form2.cb2_schaltung.Text='REMOVABLE_ALTERNATIVE')
OR (Form2.cb3_schaltung.Text='REMOVABLE_ALTERNATIVE') OR (Form2.cb4_schaltung.Text='REMOVABLE_ALTERNATIVE')) then
begin
{$ifndef OPERATOREN}
{$undef OPERATOREN}
{$endif OPERATOREN}
{$define OPERATOREN := NEGATIV_ALTERNATIVE}
end;
end;
function rechnung(a,b,ausgang : Array of Integer) : Integer;
begin
for i:=0 to Form2.StringGrid1.RowCount-1 do
begin
ausgang[i]:=a[i] OPERATOREN b[i];
end;
//look in stringGrid and serach place, where in the cols nad rows is nothink
for j:=0 to Form2.StringGrid1.ColCount-1 do
begin
if (Form2.StringGrid1.Cells[j,1] = '') then
begin
for k:=1 to Form2.StringGrid1.RowCount-1 do
begin
Form2.StringGrid1.Cells[j,k]:=IntToStr(ausgang[k-1]);
end;
break;
end;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
SetLength(e1, Form2.StringGrid1.RowCount-1);
SetLength(e2, Form2.StringGrid1.RowCount-1);
SetLength(e3, Form2.StringGrid1.RowCount-1);
SetLength(e4, Form2.StringGrid1.RowCount-1);
SetLength(z1, Form2.StringGrid1.RowCount-1);
SetLength(z2, Form2.StringGrid1.RowCount-1);
SetLength(z3, Form2.StringGrid1.RowCount-1);
SetLength(z4, Form2.StringGrid1.RowCount-1);
preprozessors;
for i:=0 to Form2.StringGrid1.ColCount-1 do
begin
if (Form2.StringGrid1.Cells[i,0] = Form2.cb1_input1.Text) then
begin
for j:=1 to Form2.StringGrid1.RowCount-1 do
begin
e1[j-1]:=StrToInt(Form2.StringGrid1.Cells[i,j]);
end;
{StringGrid1.Cells[6,6]:=IntToStr(StringGrid1.RowCount);
StringGrid1.Cells[6,7]:=IntToStr(i);}
end;//jezeli jakis element z tabeli = comboboxowi, to zatrzymaj sie i wprowadz dane do tablicy intow e1
if (Form2.StringGrid1.Cells[i,0] = Form2.cb1_input2.Text) then
begin
for k:=1 to Form2.StringGrid1.RowCount-1 do
begin
e2[k-1]:=StrToInt(Form2.StringGrid1.Cells[i,k]);
end;
end;//jezeli jakis element z tabeli = comboboxowi, to zatrzymaj sie i wprowadz dane do tablicy intow e2
end;//idz po kolei prezz wszystkie kolumny
rechnung(e1,e2,z1);
for l:=1 to Form2.StringGrid1.RowCount-1 do
begin
Form2.StringGrid1.Cells[6,l]:=IntToStr(e1[l-1]);
Form2.StringGrid1.Cells[8,l]:=IntToStr(e2[l-1]);
end;
end;
end.
Witam,
wyzej dalem kod, jako kod pokazuje mi sie:
unit2.pas(50,4) Fatal: Syntax error, ";" expected but "identifier NOR" found
Tylko, ze nie za bardzo wiem, gdzie lezy problem, bo wczesniej wszystko normalnie dzialalo, a przeciez po preprozesorach nic sie nie wstawia, bynajmiej tak czytalem, wiec myse, ze zle ich nie zaimplementowalem. Oprocz tego, gdy wybieram jakis kolwiek przycisk, w tym przypadku w comboboxie, zalozmy ALTERNATIV, to i tak pokazuje sie jako XOR i nie wiem, czy to wina tego, ze definiuje to wszystko w procedurze i nie przekazuje tego dalej, czy moze z innych powodow. Gdyby byly jakies pytania, to chetnie na nie odpowiem.
Milego dnia i pozdrawiam
DragonCoder