我在delphi中遇到多线程问题.我有一个名单(大约有2000个名字),我需要在我的网站上获取每个名字的一些数据.除线程控制外,我的系统工作正常.
我想创建10个线程,当某个线程终止时,创建另一个...直到列表的末尾.
var
Form1: TForm;
tCount: Integer; //threads count
implementation
type
TCheck = class(TThread)
public
constructor Create(Name: string);
destructor Destroy; Override;
protected
procedure Execute; Override;
end;
MainT = class(TThread)
protected
procedure Execute; Override;
end;
destructor TCheck.Destroy;
begin
Dec(tCount);
end;
procedure MainT.Execute;
var
i: Integer;
Load: TStringList;
begin
Load:=TStringList.Create;
Load.LoadFromFile('C:\mynames.txt');
for i:= 0 to Load.Count -1 do
begin
if tCount = 10 then //if we have 10 threads running...
begin
repeat
Sleep(1);
until tCount < 10;
end;
TCheck.Create(Load.Strings[i]);
TCheck.Start;
Inc(tCount);
end; …Run Code Online (Sandbox Code Playgroud) 很难解释我想要什么,所以我将展示我想要的结果的动画 gif(在 Photoshop 中制作)以及 jsFiddle 中发生的情况的代码。
\n\n\n\n正如你所看到的,当蓝色框的大小不足以容纳一行中的所有项目时,4\xc2\xba 项目被移动到第二行(如预期),但他没有居中对齐,而是被左边了对齐。
\n\n我的 CSS 代码
.outer-box\n{\n background: #00cc99;\n width: 100%;\n max-width: 800px;\n font-size: 0;\n text-align: center;\n padding: 10px;\n}\n\n.outer-box a\n{\n display: inline-block;\n width: 120px;\n height: 80px;\n padding: 10px;\n background: #ff5050;\n font-size: 12px;\n}\n\n.outer-box a:hover\n{\n background: #990000;\n}\n\n.outer-box a div\n{\n background: #99ccff;\n width: 100%;\n height: 100%;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我的 HTML
<div class="outer-box">\n <a href="#"><div>I put image and text here</div></a>\n <a href="#"><div>I put image and text here</div></a>\n <a href="#"><div>I put image and text here</div></a>\n <a …Run Code Online (Sandbox Code Playgroud) 我想知道MOV BYTE PTR指令究竟是如何工作的,我在这里有一个例子,我无法理解结果.核实:
MOV CL,BYTE PTR DS:[ESI]
----Ollydbg show this------
DS:[01EA22E0]=41 ('A')
CL=B0
Run Code Online (Sandbox Code Playgroud)
为什么CL = B0?为什么CL不是41?如果我在转储中去ESI,我就有这个
01EA22E0: 41 47 00 C5 B9 F1 63 3C... But any B0 ;(
Run Code Online (Sandbox Code Playgroud)
检查我的印刷品:

我真的需要解决这个问题,欢迎任何帮助.
这是我关于这个问题的第二个问题,我对此有一些麻烦.<
好吧,我只想创建有限数量的线程(在这种情况下,我想要10个线程),然后每个线程将在我的列表中选取一个名称并在我的站点中获取一些数据.
我的系统工作得很好,但我的多线程系统仍然失败=(
-
我尝试了LU RD发布的代码,但主线程没有等待线程完成队列,只是停止=(
代码:
uses
Classes,SyncObjs,Generics.Collections;
Type
TMyConsumerItem = class(TThread)
private
FQueue : TThreadedQueue<TProc>;
FSignal : TCountDownEvent;
protected
procedure Execute; override;
public
constructor Create( aQueue : TThreadedQueue<TProc>; aSignal : TCountdownEvent);
end;
constructor TMyConsumerItem.Create(aQueue: TThreadedQueue<TProc>; aSignal : TCountDownEvent);
begin
Inherited Create(false);
Self.FreeOnTerminate := true;
FQueue := aQueue;
FSignal := aSignal;
end;
procedure TMyConsumerItem.Execute;
var
aProc : TProc;
begin
try
repeat
FQueue.PopItem(aProc);
if not Assigned(aProc) then
break; // Drop this thread
aProc();
until Terminated;
finally
FSignal.Signal;
end;
end;
procedure …Run Code Online (Sandbox Code Playgroud) 我在将javascript函数转换为delphi时遇到了一些麻烦.除了crc部分,一切正常.
这是一个很长的问题,但我真的需要帮助.这个软件将帮助我完成我的工作.我正在使用Delphi XE3.
首先,我将发布delphi函数,以便我可以显示问题所在.
function getChlg(c: DWORD; slt: string; s1,s2: Char): string;
const
n = 4;
var
arr: array of char;
start,Endd,t: Integer;
m: Extended;
crc: DWORD;
chlg, astr: string;
//loop vars
i,j,k: integer;
begin
start:=Ord(s1);
Endd:=Ord(s2);
SetLength(arr, n);
m:=Math.Power(((Endd - start) + 1),n);
for i := 0 to 3 do
arr[i]:=s1;
for i := 0 to round(m)-1 do
begin
for j:= n-1 downto 0 do
begin
t:=Ord(arr[j]);
Inc(t);
arr[j]:=Chr(t);
if (Ord(arr[j]) <= Endd) then
break
else
arr[j]:=s1;
end; //j …Run Code Online (Sandbox Code Playgroud) 是的,有类似的问题,但没有一个解决了我的问题.我用三个项目创建了一个新的解决方案:
ICrawler.cs代码:
namespace Shared.Data.Structures
{
public interface ICrawler
{
void SayHello();
}
}
Run Code Online (Sandbox Code Playgroud)
FP.cs代码:
using System;
using Shared.Data.Structures;
namespace FirstPlugin
{
public class FP : ICrawler
{
public void SayHello() {
Console.WriteLine("Hello From FirstPlugin.dll");
}
}
}
Run Code Online (Sandbox Code Playgroud)
Program.cs代码:
using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using Shared.Data.Structures;
namespace MainApp
{
class Program
{
static void Main(string[] args) {
ICollection<ICrawler> plugins = GenericPluginLoader<ICrawler>.LoadPlugins(Directory.GetCurrentDirectory() + …Run Code Online (Sandbox Code Playgroud)