Entwickler-Ecke

Programmierwerkzeuge - OTA: Probleme mit Ansicht als Text


BenBE - So 12.06.05 20:26
Titel: OTA: Probleme mit Ansicht als Text
Hi,

hab heut ein wenig mit der OTA für einen Formular-Experten herumexperimentiert und dabei ein kleines Problem.

Mit folgendem Source erstelle ich ein neues Formular:

OIDEForm.pas
 
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
{ ... }
Const
    FormDfmSource = 'object %s: T%0:s'#13#10'end';
    myClassName = 'TOVCLForm';
    myClassParent = 'TOVCLForm';
    myClassText = '';
    myClassState = 'alpha';
    myInterfaceUses = 'Windows, Messages, SysUtils, Classes, Controls, Forms, Graphics, OVCLForm';
    myImplementationUses = 'ODbgInterface';
    DFMInclude: Boolean = True;

Procedure TOVCLFormExpert.Execute;
Var
    UnitIdent, FileName: String;
    FormName: String;
    CodeStream: TStreamAdapter;
    DFMStream: TStreamAdapter;
    DFMString: TStringStream;
    DFMVCLStream: TMemoryStream;
Begin
    //BenBE: Check if there's an open project ATM
    If ToolServices.GetProjectName = '' then
    Begin
        MessageDlg('Es muss ein Projekt geöffnet sein, um ein neues Omorphia-Formular erzeugen zu können.', mtError, [mbOk], 0);
        Exit;
    end;

    //Neo: Try to get a new Unit name
    If Not ToolServices.GetNewModuleName(UnitIdent, FileName) Then
        Exit;

    FormName := Copy(myClassName, 2, Length(myClassName)) + Copy(UnitIdent, 5255);
    CodeStream := TStreamAdapter.Create(TStringStream.Create(MakeUnit(UnitIdent, FormName, myClassState, myClassParent, myInterfaceUses, myImplementationUses, myClassText, DFMInclude)));

{
    //Neo: Create a Binary DFM module
    DFMString := TStringStream.Create(Format(FormDfmSource, [FormName]));
    Try
        DFMVCLStream := TMemoryStream.Create;
        Try
            ObjectTextToResource(DFMString, DFMVCLStream);
            DFMVCLStream.Position := 0;
            DFMStream := TStreamAdapter.Create(DFMVCLStream);
            ToolServices.CreateModuleEx(FileName, FormName, myClassName, '', CodeStream, DFMStream, [cmAddToProject, cmShowSource, cmShowForm, cmUnnamed, cmMarkModified]);
        Except
            DFMVCLStream.Free;
        End;
    Finally
        DFMString.Free;
    End;
}


    //BenBE: Create a Text DFM Formular resource
    DFMString := TStringStream.Create(Format(FormDfmSource, [FormName]));
    DFMString.Position := 0;
    DFMStream := TStreamAdapter.Create(DFMString);
    Try
        ToolServices.CreateModuleEx(FileName, FormName, myClassName, '', CodeStream, DFMStream, [cmAddToProject, cmShowSource, cmShowForm, cmUnnamed, cmMarkModified]);
    Except
        DFMStream.Free;
    End;
End;


Die Function MakeUnit erzeugt den Rohquelltext einer neuen Unit, der auch Syntaktisch korrekt ist.

Soweit funktioniert das auch, jedoch habe ich folgendes Problem:

Wenn ich auf dem erzeugten Formular den Punkt "Ansicht als Text" auswähle, bringt Delphi mir eine EConvertError-Exception 'Ungültiges Argument zum Codieren des Datums.' Allerdings kann ich nicht nachvollziehen, was Delphi damit meint.
Nehm ich jedoch ein Standard-Form von Delphi, funktioniert alles wie gewünscht.

Wer kann mir da helfen?

P.S.: So sieht der erzeugte Unit-Source aus:


Unit2.pas
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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Unit Unit2;
// *****************************************************************************
// Omorphia Library V0.0 - Planning State
// Library Include Submodule
//  
// OVCLForm2 - alpha
// 
// *****************************************************************************
// To Do:
//
// *****************************************************************************
// News:
//
// *****************************************************************************
// Bugs:
//
// *****************************************************************************
// Info:
//  [*] unit created by TOVCLForm expert
// *****************************************************************************
{$I Omorphia.config.inc}

Interface

Uses
    Windows,
    Messages,
    SysUtils,
    Classes,
    Controls,
    Forms,
    Graphics,
    OVCLForm;

Type
    TOVCLForm2 = class(TOVCLForm)
    Private
    Protected
    Public
    Published
    End;

Var
    OVCLForm2: TOVCLForm2;

Implementation

Uses
    ODbgInterface;

{$R *.dfm}

End.


alzaimar - So 12.06.05 20:32

Geht speichern? Dann einfach die DFM im Notepad öffnen.
Oder es liegt an der inc-Datei...


BenBE - So 12.06.05 21:20

Speichern geht und er legt auch sowohl PAS als auch DFM korrekt an.

die INC-Datei ist im Suchpfad\Bibliothekspfad von Delphi verfügbar und steuert einige Bedingte Compilierungen für die einzelnen Delphi-Versionen. Die INC-File funktioniert zuverlässig in normalen Delphi-Units.


alzaimar - So 12.06.05 21:25

Und? was steht so innner DFM-Datei? Kein Datum? Nix? Tät mich ja wundern....


BenBE - So 12.06.05 21:31


Unit2.dfm
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
object OVCLForm2: TOVCLForm2
  Left = 190
  Top = 106
  Width = 320
  Height = 240
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  UseXPManifest = False
  ScreenIndex = 0
  PixelsPerInch = 96
  TextHeight = 13
end


NeoInDerMATRIX - So 12.06.05 21:55

Hi,

warum speicherst du extra TextFormat! Mit BIN ging es doch!

Cu
Neo


BenBE - So 12.06.05 22:58

Mit BIN tritt genau das gleiche Problem auf.


BenBE - Mo 13.06.05 17:53

Hab nochmal nachgeguckt und einen API-Fehler-Code 2 beim Laden der DFM-File von HDD bei Property ScreenIndex (neu in dieser Klasse). Ich werd also Neo mal anquatschen müssen. THX vorerst.