如何使用Delphi提取HTML文件中所有图像的地址,例如使用HTML解析器?
我有一个函数来检查数组中是否有重复数据;这看起来像下图所示。任务是使用该函数查找矩阵中没有重复数据的列。问题是如何将矩阵的列传递给该函数。
PS 我正在使用 Pascal/Delphi
type
myArray = array [1..10] of integer;
function noRepeat(A: myArray; n: integer): Boolean;
var
i: integer;
begin
Result := true;
for i:=1 to n do
for j := i + 1 to n do
if (A[i] = A[j]) then
Result := true;
end;
Run Code Online (Sandbox Code Playgroud) 当我写入Pascal中的外部文件时,即使编码完美无缺,外部文件也不会完全写入.
procedure save;
{Menyimpan data penerbangan ke dalam file eksternal}
begin
write('> ');
write('nama file: ');
readln(namafisik);
assign(d,namafisik);
{$I-};
rewrite(d);
{$I+};
if (IOresult=0) then
begin
for i:=1 to Neff do
writejadwal(i);
end;
end;
procedure writejadwal(i:integer);
{Menuliskan jadwal ke file eksternal pada indeks ke-i}
begin
write(d,T.KodePenerbangan[i]);
write(d,' | ');
write(d,T.KotaKeberangkatan[i]);
write(d,' | ');
write(d,T.KotaKedatangan[i]);
write(d,' | ');
if ((T.TKeberangkatan[i].Day) < 10 ) then
begin
x:=T.TKeberangkatan[i].Day;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKeberangkatan[i].Day);
end;
write(d,':');
if ((T.TKeberangkatan[i].Month) < 10 ) then
begin …Run Code Online (Sandbox Code Playgroud) pascal procedural-programming freepascal lazarus turbo-pascal
以下是我正在处理的文件预览系统项目的示例.主窗体上有两个ListBox.第一个[lst_fileList]显示目录[files]中所有".txt"文件的列表,每个文件都标有[order ###.txt],###是1到999之间的任意数字.程序运行后,它会在列表框中找到所选项目(.txt文件),然后在第二个ListBox [lst_filePreview]上显示文件中的每一行.
虽然在运行它时,ReadLn(selectedFile)的第21行发生错误.错误状态(不兼容类型:得到"无类型",预期"AnsiString").
我已经看了几个小时这个错误,无济于事...任何帮助将不胜感激,谢谢.
procedure TForm1.btn_getPreviewClick(Sender: TObject);
var
checkSelect:integer;
orderSelect:string;
i:integer;
selectedFile:textFile;
begin
if lst_fileList.SelCount > 0 then
begin
for checkSelect:= 0 to (lst_fileList.Items.Count - 1) do
if lst_fileList.Selected [checkSelect] then
begin
orderSelect:=lst_fileList.Items[checkSelect];
orderSelect:=RightStr(orderSelect,3);
if fileexists('files\order'+orderSelect+'.txt') then
begin
assignFile(selectedFile,'files\order'+orderSelect+'.txt');
reset(selectedFile);
while not EOF(selectedFile) do
begin
lst_filePreview.Items.Add(readLn(selectedFile)); // Error occurs here: //
end;
closeFile(selectedFile);
end;
end;
end else
ShowMessage('Please select an item first!');
end;
Run Code Online (Sandbox Code Playgroud) 首先,我使用Mingw 4.8作为代码中的C++ DLL的编译器:块13.12和Lazarus 1.4.2用于处理pascal代码.(windows 7)
我需要在c ++或c中生成一个可以从pascal程序调用的dll.
问题是我的关于pascal的知识是空的,制作一个简单的程序看起来并不复杂,但我找不到关于如何导入和使用C/C++ DLL的好信息.
唯一没有用的是:http://www.drbob42.com/delphi/headconv.htm 我的真实代码:
帕斯卡尔:
funtion hello():Integer; external 'function' index 1;
...
Label1.Caption:=IntToStr(hello());
Run Code Online (Sandbox Code Playgroud)
C++ DLL头:
#ifndef function_H
#define function_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BUILDING_DLL
#define FUNCTION_DLL __declspec(dllexport)
#else
#define FUNCTION_DLL __declspec(dllimport)
#endif
int __stdcall FUNCTION_DLL hello( );
#ifdef __cplusplus
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)
C++文件:
#include <stdio.h>
#include "function.h"
__stdcall int hello( )
{
return 8;
}
Run Code Online (Sandbox Code Playgroud)
但是当试图传递任何参数或做一些复杂的函数时,开始给出randoms数字.
这是新代码:Pascal:
function function1(t1:Integer):Integer; external 'function' index 1;
...
entero:=8;
Label1.Caption:=IntToStr(function1(entero2));
Run Code Online (Sandbox Code Playgroud)
我还将c …
在C中,您可以在一行中分配两个变量
b = a = sqrt(10);
Run Code Online (Sandbox Code Playgroud)
在德尔福
b := a := Sqrt(10);
Run Code Online (Sandbox Code Playgroud)
不被允许.
有了Delphi中讨论IfThen的三元运算符?:的"替代" - 相当于C#的三元运算符?总之,IfThen似乎并非绝对必要.
所以也许还有这样的东西:
function AssignAndReturn(var LHS: Integer; RHS: Integer): Integer;
begin
LHS := RHS;
Result := RHS;
end;
(...)
var
a, b: Integer;
begin
b := AssignAndReturn(a, Round(Sqrt(10)));
Run Code Online (Sandbox Code Playgroud)
我不是想"让一切看起来像C".我刚才注意到,有时再次在同一行中"重用"赋值的右侧会很好.(参见Lazarus/Free Pascal:如何改进while循环的编码风格(避免使用无限循环),例如,每次传递都会重新分配布尔表达式.)
如何将值转换为与lparamWindows消息中的值相同的形式?
X := SMALLINT(lParam and $FFFF);
Y := SMALLINT((lParam shr 16) and $FFFF);
Run Code Online (Sandbox Code Playgroud)
所以lparam转换成Word.如何进行逆向转换?
他们让我把一组字样表示成"地图记忆".集合中有哪些字符?老师告诉我们使用ASCII码,成一组32个字节.
A有这个例子,集{'A','B','C'}
(7来自0111)
= {00 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 00}
FreePascal,Delphi模式。经过一些实验,我发现该代码已编译,FPC告诉我类过程必须是“静态的”。但是我的问题是:那为什么运算符Equal不需要“静态”并且可以正常编译?我也无法理解“类”过程和“类”与“静态”有什么区别(例如,在Python中,classmethod您获取参数-引用该类,在staticmethod-中您没有此类参数)。
type TPos = record
FLine: Word;
FPos: Word;
class procedure Init(out a: TPos); static;
class operator Equal(a, b: TPos): Boolean;
end;
Run Code Online (Sandbox Code Playgroud)
PS。我设置“ delphi”标签的原因是:1)它是在delphi模式下编写的2)因为我找到了与Delphi相同的文档:关于类和静态关键字。