假设我在delphi项目中有两个表单,我希望能够从form2访问form1的变量.是否有人声明,在form1中可以从所有表单中读取一个"公共"变量?
我试过在公共声明中添加一个变量
{ private declarations }
public
{ public declarations }
test: integer;
end;
Run Code Online (Sandbox Code Playgroud)
在形式2我有
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, unit1;
type
{ TForm2 }
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.lfm}
{ TForm2 }
procedure TForm2.FormCreate(Sender: TObject);
begin
form1 //<---------- DOES NOT GET RECOGNIZED
end;
end.
Run Code Online (Sandbox Code Playgroud)
然后我将'Unit1'放入Form2的使用部分,但由于循环引用,我似乎无法做到这一点.如果可能的话,我想不要使用指针.
我试图在运行时为图像(Image1)分配图像.
因为我无法设置要从资源加载的属性.所以我需要在运行时加载.
我有代码
procedure TForm1.FormCreate(Sender: TObject);
var RS:Tresourcestream ;
begin
RS := TResourceStream.Create(HInstance,'Splashscreen_Background', RT_RCDATA);
image1.Picture.Bitmap.LoadFromResourcename(HInstance,'splashscreen_background');
end;
Run Code Online (Sandbox Code Playgroud)
但它只是加载带有空白图像的表单.以及:
procedure TForm1.FormCreate(Sender: TObject);
BitMap1 : TBitMap;
begin
BitMap1 := TBitMap.Create;
BitMap1.LoadFromResourceName(HInstance,'Live');
image1.Picture.Bitmap.Assign(Bitmap1);
end;
Run Code Online (Sandbox Code Playgroud)
我不知道底部是否可以工作,猜不是.只是我试过的东西.

出于某种原因,即使我昨天使用它,我的OpenID帐户也不再存在.但无论如何.
我需要将记录数据保存到.dat文件中.我尝试了很多搜索,但它都与数据库和BLOB有关.我无法从中构建任何东西.
我有以下记录
type
Scores = record
name: string[50];
score: integer;
end;
var rank: array[1..3] of scores;
Run Code Online (Sandbox Code Playgroud)
我只需要一种简单的方法来保存和读取.dat文件中的记录数据.我有关于如何做到的书,但那是在学校.
在Visual Studio 2010 Express [VB.NET]中,如果我通过Application属性>编译>高级编译选项将目标框架从4.0更改为framework 2.0,我会得到一个错误列表:
Warning 5 The referenced component 'System.Xml.Linq' could not be found.
Warning 6 The referenced component 'System.Data.DataSetExtensions' could not be found.
Warning 4 The referenced component 'System.Core' could not be found.
Warning 2 The primary reference "System.Xml.Linq", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Xml.Linq" or retarget your application to a framework version which contains "System.Xml.Linq". WindowsApplication3
Warning 3 …Run Code Online (Sandbox Code Playgroud) 说我有变量:
Var question : array[1..50] of char;
Run Code Online (Sandbox Code Playgroud)
当我做:
question := 't'; //What is the correct way to change the value?
Run Code Online (Sandbox Code Playgroud)
它返回一个错误:
不兼容的类型:'char'的数组[1..50]和'Char'
注意:我希望最大字符串大小为50个字符,而不是50个不同的字符.
这个问题的原因是我在另一个单元中有一个记录(这只是一个基本的例子,而不是我上面写的那个)在那个单元里我有一个Record,我不能使用字符串数据类型(或者有办法吗?请说明是否有).我只需要知道如何为一组字符赋值.
问题一
我有
var example : array[0..15] of char;
Run Code Online (Sandbox Code Playgroud)
我想将输入值分配给该变量
example := inputbox('Enter Name', 'Name', '');
Run Code Online (Sandbox Code Playgroud)
在高分单元中,我有记录和数组
type
points = record
var
_MemoryName : array[0..15] of char;
_MemoryScore : integer;
end;
var
rank : array[1..3] of points;
Run Code Online (Sandbox Code Playgroud)
var s: string;
a: packed array[0..15] of char;
highscoresdata.position[1]._MemoryName := StrPLCopy(a, s, Length(a)) ;
Run Code Online (Sandbox Code Playgroud)
返回 - >(186): E2010 Incompatible types: 'array[0..15] of Char' and 'PWideChar'
var s: string;
a: packed array[0..15] of char;
s := InputBox('caption', 'Caption', 'Caption');
FillChar(a[0], length(a) * sizeof(char), #0);
Move(s[1], …Run Code Online (Sandbox Code Playgroud) 我有2个结构
Public Structure One
Public ItemOne As String
Public ItemTwo As Integer
End Structure
Public Structure Two
Public ItemOne As String
Public ItemTwo As Integer
Public ItemThree As Integer
Public ItemFour As Integer
Public ItemFive As Integer
End Structure
Public TestOne(0) as One
Public TestTwo(19) as Two
Run Code Online (Sandbox Code Playgroud)
使用FileOpen,FilePut和FileClose方法,我收到一个错误:(作为示例,仅限于相关代码)
Public Sub WriteOne()
FileOpen(1, "One.dat", OpenMode.Random, OpenAccess.Write)
FilePut(1, TestOne)
FileClose(1)
End Sub
Public Sub ReadOne()
FileOpen(1, "One.dat", OpenMode.Random, OpenAccess.Read)
FileGet(1, TestOne)
FileClose(1)
End Sub
Public Sub WriteTwo()
FileOpen(1, "Two.dat", OpenMode.Random, OpenAccess.Write)
FilePut(1, …Run Code Online (Sandbox Code Playgroud)