Hej
Er rimelig nybegynder, men har fundet en tut og fulgt den. Mit problem er at den ikke gider at kører koden altså lave en .exe fil, så jeg kan se programmet.
Her er koden:
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, DB, DBClient, ComCtrls, Menus,
StdCtrls, Mask;
type
TfrmMain = class(TForm)
mnuMain: TMainMenu;
mnuFiler: TMenuItem;
itmFilerLuk: TMenuItem;
N6: TMenuItem;
itmFilerGem: TMenuItem;
itmFilerAben: TMenuItem;
itmFilNy: TMenuItem;
stbStatus: TStatusBar;
edtNavn: TDBEdit;
edtTelefon: TDBEdit;
edtMobil: TDBEdit;
mmoAdresse: TDBMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
edtArbejde: TDBEdit;
edtEmail: TDBEdit;
DBNavigator: TDBNavigator;
Navigation1: TMenuItem;
itmNaviForste: TMenuItem;
itmNaviFrem: TMenuItem;
itmNaviTilbage: TMenuItem;
itmNaviSidste: TMenuItem;
N2: TMenuItem;
itmNaviFind: TMenuItem;
Bevel1: TBevel;
itmPosterNy: TMenuItem;
itmPosterSlet: TMenuItem;
N4: TMenuItem;
cdsAdresser: TClientDataSet;
dsAdresser: TDataSource;
mnuNavigation: TMenuItem;
itmPosterRet: TMenuItem;
itmPosterOpdater: TMenuItem;
itmPosterFortryd: TMenuItem;
fldNavn: TStringField;
fldAdresse: TMemoField;
fldTelefon: TStringField;
fldMobil: TStringField;
fldArbejde: TStringField;
fldEmail: TStringField;
diaOpen: TOpenDialog;
diaSave: TSaveDialog;
procedure itmFilNyClick(Sender: TObject);
procedure itmFilerAbenClick(Sender: TObject);
procedure itmFilerLukClick(Sender: TObject);
procedure itmFilerGemClick(Sender: TObject);
procedure itmPosterNyClick(Sender: TObject);
procedure itmPosterRetClick(Sender: TObject);
procedure itmPosterSletClick(Sender: TObject);
procedure itmPosterOpdaterClick(Sender: TObject);
procedure itmPosterFortrydClick(Sender: TObject);
procedure itmFilerUdskrivClick(Sender: TObject);
procedure itmNaviForsteClick(Sender: TObject);
procedure itmNaviFremClick(Sender: TObject);
procedure itmNaviTilbageClick(Sender: TObject);
procedure itmNaviSidsteClick(Sender: TObject);
procedure itmNaviFindClick(Sender: TObject);
procedure cdsAdresserAfterOpen(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
uses
Printers;
{$R *.dfm}
procedure TfrmMain.itmFilNyClick(Sender: TObject);
begin
cdsAdresser.Close;
cdsAdresser.CreateDataSet;
if diaSave.Execute then
begin
cdsAdresser.FileName := diaSave.FileName;
cdsAdresser.Open;
end;
end;
procedure TfrmMain.itmFilerAbenClick(Sender: TObject);
begin
cdsAdresser.Close;
if diaOpen.Execute then
begin
cdsAdresser.FileName := diaOpen.FileName;
cdsAdresser.Open;
end;
end;
procedure TfrmMain.itmFilerGemClick(Sender: TObject);
begin
if diaSave.Execute then
begin
cdsAdresser.FileName := diaSave.FileName;
cdsAdresser.SaveToFile;
end;
end;
procedure TfrmMain.itmFilerUdskrivClick(Sender: TObject);
var
X, Y : Integer;
H, W : Integer;
idx : integer;
adr : TStrings;
T : String;
begin
Printer.BeginDoc;
try
H := Printer.PageHeight;
W := Printer.PageWidth;
X := 200;
Y := 200;
adr := TStringList.Create;
cdsAdresser.First;
while not cdsAdresser.Eof do
begin
if Y > (H - 400) then
Y := 200;
T := cdsAdresser.FieldByName('Navn').AsString;
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
adr.Text := cdsAdresser.FieldByName('Adresse').AsString;
for idx := 0 to adr.Count - 1 do
begin
T := adr[idx];
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
end;
T := cdsAdresser.FieldByName('Telefon').AsString;
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
T := cdsAdresser.FieldByName('Mobil').AsString;
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
T := cdsAdresser.FieldByName('Arbejde').AsString;
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
T := cdsAdresser.FieldByName('Email').AsString;
Printer.Canvas.TextOut(X, Y, T);
Y := Y + Printer.Canvas.TextHeight(T) + 25;
Printer.Canvas.Polyline([Point(X, Y), Point(X + (W-400), Y)]);
Y := Y + 25;
cdsAdresser.Next;
end;
finally
Printer.EndDoc;
end;
end;
procedure TfrmMain.itmFilerLukClick(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.itmPosterNyClick(Sender: TObject);
begin
if cdsAdresser.State = dsBrowse then
cdsAdresser.Insert;
end;
procedure TfrmMain.itmPosterRetClick(Sender: TObject);
begin
if cdsAdresser.State = dsBrowse then
if (not cdsAdresser.Bof) and (not cdsAdresser.Eof) then
cdsAdresser.Edit;
end;
procedure TfrmMain.itmPosterSletClick(Sender: TObject);
begin
if cdsAdresser.State = dsBrowse then
if (not cdsAdresser.Bof) and (not cdsAdresser.Eof) then
cdsAdresser.Delete;
end;
procedure TfrmMain.itmPosterOpdaterClick(Sender: TObject);
begin
if cdsAdresser.State in [dsEdit, dsInsert] then
cdsAdresser.Post;
end;
procedure TfrmMain.itmPosterFortrydClick(Sender: TObject);
begin
if cdsAdresser.State in [dsEdit, dsInsert] then
cdsAdresser.Cancel;
end;
procedure TfrmMain.itmNaviForsteClick(Sender: TObject);
begin
cdsAdresser.First;
end;
procedure TfrmMain.itmNaviFremClick(Sender: TObject);
begin
if not cdsAdresser.Eof then
cdsAdresser.Next
else
cdsAdresser.First;
end;
procedure TfrmMain.itmNaviTilbageClick(Sender: TObject);
begin
if not cdsAdresser.Bof then
cdsAdresser.Prior
else
cdsAdresser.Last;
end;
procedure TfrmMain.itmNaviSidsteClick(Sender: TObject);
begin
cdsAdresser.Last;
end;
procedure TfrmMain.itmNaviFindClick(Sender: TObject);
var
navn : String;
begin
if InputQuery('Navn', 'Indtast navn', navn) then
cdsAdresser.Locate('Navn', navn, [loCaseInsensitive, loPartialKey]);
end;
procedure TfrmMain.cdsAdresserAfterOpen(DataSet: TDataSet);
begin
stbStatus.SimpleText := IntToStr(cdsAdresser.RecordCount) + ' poster';
end;
end.
Nogle der lige gider fortælle mig hvad der er gået galt?
/Jacob